Skip to main content

vtcode_core/cli/args/
version.rs

1use super::*;
2
3pub(super) fn parse_workspace_directory(raw: &str) -> Result<PathBuf, String> {
4    let candidate = PathBuf::from(raw);
5    if !candidate.exists() {
6        return Err(format!(
7            "'{}' is not a valid workspace path or subcommand.\n\
8             Run `vtcode --help` to see available commands and options.",
9            raw
10        ));
11    }
12
13    Ok(candidate)
14}
15
16/// Multi-line `--version` report whose first line is the caller-supplied
17/// build stamp (`{version}+{sha}[.dirty]` from the root build script, or the
18/// bare crate version). The stamp is a parameter — not `option_env!` — because
19/// `cargo:rustc-env` never crosses package boundaries, so only the root crate
20/// can read what its own build script sets. Keep the stamp to a single token:
21/// the desktop updater parses this first line strictly.
22pub fn long_version(git_info: &str) -> String {
23    let path_diagnostics = match vtcode_commons::VtCodePaths::resolve() {
24        Ok(paths) => format!(
25            "Config directory: {}\nData directory: {}\nState directory: {}\nCache directory: {}\nRuntime directory: {}\nExecutable directory: {}\nLegacy directory: {}\nMigration marker: {}\nMigration report: {}",
26            paths.config_dir().display(),
27            paths.data_dir().display(),
28            paths.state_dir().display(),
29            paths.cache_dir().display(),
30            paths.runtime_dir().display(),
31            paths.executable_dir().display(),
32            paths.legacy_dir().display(),
33            paths.migration_marker_path().display(),
34            paths.migration_report_path().display(),
35        ),
36        Err(error) => format!("Storage paths: unavailable ({error:#})"),
37    };
38    let environment = [
39        "HOME",
40        "VTCODE_HOME",
41        "VTCODE_CONFIG",
42        "VTCODE_CONFIG_PATH",
43        "VTCODE_DATA",
44        "CODEX_HOME",
45        "XDG_CONFIG_HOME",
46        "XDG_DATA_HOME",
47        "XDG_STATE_HOME",
48        "XDG_CACHE_HOME",
49        "XDG_RUNTIME_DIR",
50        "XDG_BIN_HOME",
51        "XDG_CONFIG_DIRS",
52        "XDG_DATA_DIRS",
53    ]
54    .iter()
55    .map(|name| {
56        let value = env::var_os(name)
57            .map(|value| value.to_string_lossy().into_owned())
58            .unwrap_or_else(|| "<not set>".to_string());
59        format!("  {name}={value}")
60    })
61    .collect::<Vec<_>>()
62    .join("\n");
63
64    format!(
65        "{}\n\nAuthors: {}\n{}\n\nEnvironment variables:\n{}",
66        git_info,
67        env!("CARGO_PKG_AUTHORS"),
68        path_diagnostics,
69        environment,
70    )
71}