Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions crates/ov_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl CliContext {
#[derive(Parser)]
#[command(name = "openviking")]
#[command(about = "OpenViking - An Agent-native context database")]
#[command(version = env!("CARGO_PKG_VERSION"))]
#[command(disable_version_flag = true)]
#[command(arg_required_else_help = true)]
struct Cli {
/// Output format
Expand All @@ -53,8 +53,12 @@ struct Cli {
#[arg(short, long, global = true, default_value = "true")]
compact: bool,

/// Show CLI and server version
#[arg(short = 'V', long = "version")]
version: bool,

#[command(subcommand)]
command: Commands,
command: Option<Commands>,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -377,8 +381,6 @@ enum Commands {
#[command(subcommand)]
action: ConfigCommands,
},
/// Show CLI version
Version,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -514,6 +516,43 @@ enum ConfigCommands {
async fn main() {
let cli = Cli::parse();

if cli.version {
// Print CLI version
println!("CLI version: {}", env!("CARGO_PKG_VERSION"));

// Try to get server version
let output_format = cli.output;
let compact = cli.compact;
if let Ok(ctx) = CliContext::new(output_format, compact) {
let client = ctx.get_client();
let health_result: Result<serde_json::Value> = client.get("/health", &[]).await;
match health_result {
Ok(response) => {
if let Some(version) = response.get("version").and_then(|v| v.as_str()) {
println!("Server version: {}", version);
} else {
println!("Server version: unknown");
}
}
Err(_) => {
println!("Server: not found");
let config_path = if let Ok(env_path) = std::env::var("OPENVIKING_CLI_CONFIG_FILE") {
env_path
} else {
match config::default_config_path() {
Ok(path) => path.to_string_lossy().to_string(),
Err(_) => "~/.openviking/ovcli.conf".to_string(),
}
};
println!("Check ovcli.conf: {}", config_path);
}
}
} else {
println!("Server: not found");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bug] (blocking) When CliContext::new() fails (most commonly because the config file is missing or malformed), this branch prints "Server: not found", which is misleading — the actual problem is that the config couldn't be loaded, so the CLI doesn't even know the server's address.

Additionally, unlike the Err(_) branch on line 538 which shows the config path hint, this branch omits it — precisely in the scenario (missing config) where the hint is most needed.

Suggested fix:

} else {
    println!("Server: config not loaded");
    let config_path = if let Ok(env_path) = std::env::var("OPENVIKING_CLI_CONFIG_FILE") {
        env_path
    } else {
        match config::default_config_path() {
            Ok(path) => path.to_string_lossy().to_string(),
            Err(_) => "~/.openviking/ovcli.conf".to_string(),
        }
    };
    println!("Check ovcli.conf: {}", config_path);
}

}
return;
}

let output_format = cli.output;
let compact = cli.compact;

Expand All @@ -525,7 +564,10 @@ async fn main() {
}
};

let result = match cli.command {
let result = match cli.command.unwrap_or_else(|| {
eprintln!("No command provided. Use --help for usage.");
std::process::exit(1);
}) {
Commands::AddResource {
path,
to,
Expand Down Expand Up @@ -629,10 +671,6 @@ async fn main() {
cmd.run().await
}
Commands::Config { action } => handle_config(action, ctx).await,
Commands::Version => {
println!("{}", env!("CARGO_PKG_VERSION"));
Ok(())
}
Commands::Read { uri } => handle_read(uri, ctx).await,
Commands::Abstract { uri } => handle_abstract(uri, ctx).await,
Commands::Overview { uri } => handle_overview(uri, ctx).await,
Expand Down
Loading