feat(config): move config file to XDG location #11
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/xdg-config-path"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Moves the config file to the XDG Base Directory location and creates the app's subdirectory with restrictive permissions so it can safely hold the API token.
$XDG_CONFIG_HOME/youtrack-cli/config.yaml, with~/.config/youtrack-cli/config.yamlas the fallback whenXDG_CONFIG_HOMEis unset or empty.~/.youtrack-cli.yamlis no longer honored. Users with state at the old location need to re-runauth login; nothing is auto-migrated.0o700only when missing; an existing~/.configor$XDG_CONFIG_HOMEkeeps its current mode, so we don't surprise other tools by locking down a shared dir.0o600(unchanged).--config <path>) and env var (YOUTRACK_CLI_CONFIG) still work as before.This is a deliberate divergence from the Go CLI; CLAUDE.md and README.md are updated to call that out and to point newcomers at
auth loginas the path-creating entry point.What changed
src/config.rs:Config::default_path()now composesxdg_config_home().join("youtrack-cli/config.yaml"). XDG resolution is factored into a pureresolve_xdg_config_home(xdg, home) -> Result<PathBuf>so it is unit-testable without touching process env.write_securenow callsensure_app_dirwhich creates ancestors with the platform default mode and the immediate parent with0o700.src/cli.rs:--confighelp string updated to reflect the new default.README.md: configuration section rewritten aroundauth loginand the XDG path.CLAUDE.md(project): project overview and repo-layout entries updated; the "drop-in replacement" language is replaced with a note explaining the deliberate XDG divergence.Tests
xdg_set_wins_over_home,xdg_empty_falls_back_to_home_config,xdg_unset_falls_back_to_home_config,xdg_missing_home_errors: cover the four XDG resolution cases as a pure function.save_creates_app_subdir_mode_700(Unix only): saves into a non-existent<tmp>/youtrack-cli/config.yamland asserts the parent dir ends up0o700and the file0o600.save_creates_ancestor_dirs_when_missing(Unix only): saves into a deeper non-existent path and asserts it lands on disk.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test --all-targetsgreen locally.Test plan
~/.config/youtrack-cli, runyoutrack-cli auth login --base-url https://<instance>. Confirm: the directory is created0o700, the file is created0o600, and~/.youtrack-cli.yamlis NOT touched.XDG_CONFIG_HOME=/tmp/xdg-testand re-runauth login. Confirm the file lands at/tmp/xdg-test/youtrack-cli/config.yamland not under~/.config/.~/.configexists already (typical), confirm its mode is unchanged after runningauth login.youtrack-cli config showreads from the new path without any extra flag.Notes
~/.youtrack-cli.yamlfrom a previous install is silently ignored. The "config file not found" error message already points users atauth login, so the recovery path is one command.