fix: harden Cub CLI runtime fallbacks
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -210,7 +210,16 @@ fn run_command(
|
|||||||
fn launch_tui_or_help() -> Result<(), Box<dyn std::error::Error>> {
|
fn launch_tui_or_help() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
#[cfg(feature = "tui")]
|
#[cfg(feature = "tui")]
|
||||||
{
|
{
|
||||||
cub_tui::run()?;
|
use std::io::IsTerminal;
|
||||||
|
|
||||||
|
if io::stdin().is_terminal() && io::stdout().is_terminal() {
|
||||||
|
if let Err(error) = cub_tui::run() {
|
||||||
|
eprintln!("Failed to launch cub TUI: {error}");
|
||||||
|
print_help_text()?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print_help_text()?;
|
||||||
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,20 +434,26 @@ fn sync_sources() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let bur_dir = sync_bur_repo()?;
|
let bur_dir = sync_bur_repo()?;
|
||||||
let store = init_cub_store()?;
|
let store = init_cub_store()?;
|
||||||
let aur_client = AurClient::new();
|
let aur_client = AurClient::new();
|
||||||
let sample_results = aur_client.search("a", Some("name"))?;
|
let aur_status = match aur_client.search("a", Some("name")) {
|
||||||
|
Ok(results) => format!("ok ({})", results.len()),
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("Warning: failed to refresh live AUR metadata: {error}");
|
||||||
|
format!("warning ({error})")
|
||||||
|
}
|
||||||
|
};
|
||||||
let stamp_path = store.sources_dir().join(AUR_SYNC_STAMP_FILE);
|
let stamp_path = store.sources_dir().join(AUR_SYNC_STAMP_FILE);
|
||||||
fs::write(
|
fs::write(
|
||||||
&stamp_path,
|
&stamp_path,
|
||||||
format!(
|
format!(
|
||||||
"synced_at_unix = {}\naur_sample_results = {}\n",
|
"synced_at_unix = {}\naur_status = {:?}\n",
|
||||||
current_unix_timestamp(),
|
current_unix_timestamp(),
|
||||||
sample_results.len()
|
aur_status
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("Refreshed BUR cache at {}.", bur_dir.display());
|
println!("Refreshed BUR cache at {}.", bur_dir.display());
|
||||||
println!(
|
println!(
|
||||||
"Verified live AUR metadata access and wrote sync stamp to {}.",
|
"Recorded AUR sync status and wrote sync stamp to {}.",
|
||||||
stamp_path.display()
|
stamp_path.display()
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -683,6 +698,15 @@ fn query_local_files(
|
|||||||
package: &str,
|
package: &str,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let package_name = PackageName::new(package.to_string())?;
|
let package_name = PackageName::new(package.to_string())?;
|
||||||
|
let library = context.open_library()?;
|
||||||
|
let installed_packages = library.get_installed_packages()?;
|
||||||
|
if !installed_packages.contains(&package_name) {
|
||||||
|
return Err(Box::new(CubError::PackageNotFound(format!(
|
||||||
|
"{package} is not installed under {}",
|
||||||
|
context.install_path.display()
|
||||||
|
))));
|
||||||
|
}
|
||||||
|
|
||||||
let package_state = PackageState::from_sysroot(&context.install_path)?;
|
let package_state = PackageState::from_sysroot(&context.install_path)?;
|
||||||
let install_state = package_state.installed.get(&package_name).ok_or_else(|| {
|
let install_state = package_state.installed.get(&package_name).ok_or_else(|| {
|
||||||
CubError::PackageNotFound(format!("{package} is not installed under {}", context.install_path.display()))
|
CubError::PackageNotFound(format!("{package} is not installed under {}", context.install_path.display()))
|
||||||
|
|||||||
Reference in New Issue
Block a user