Skip to content

feat: surface active TOML config path in --help (issue #213)#224

Merged
inureyes merged 1 commit into
mainfrom
feat/issue-213-config-path-help
May 24, 2026
Merged

feat: surface active TOML config path in --help (issue #213)#224
inureyes merged 1 commit into
mainfrom
feat/issue-213-config-path-help

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Closes #213.

Adds the resolved TOML config file location to all-smi --help, introduces a strictly read-only all-smi config path subcommand for scripting/discovery, and fills the config-path gap in the man page FILES section.

Before

all-smi --help did not reveal where the config file lives. The only pointer was the --config <PATH> flag description, which redirected to all-smi config init — a command that writes a file as a side effect. A new user had no way, from -h / --help alone, to know a config file even existed or where it would go.

After

  • all-smi --help and all-smi -h show a new "Configuration file" section with the resolved per-user path ($HOME / $XDG_CONFIG_HOME / %APPDATA% aware) plus an (active) / (not found) marker.
  • all-smi config path [--json] prints the active path + ordered candidate search list with no file writes. The JSON form has a stable schema (active, exists, overridden, search_order).
  • --config <PATH> is honoured by config path (reports the override + suppresses the search list).
  • Man page FILES enumerates per-platform config.toml paths and points at the new discovery surface.
  • README adds config path to the helpers list and tightens the --config flag wording.

Implementation notes

  • Dynamic after_help is composed at runtime in cli::build_command_with_runtime_help() because the resolved path embeds the user's $HOME / $XDG_CONFIG_HOME, which a static #[command(after_help = ...)] cannot do.
  • main.rs parses via Cli::from_arg_matches so the runtime composition reaches --help.
  • Shared paths::format_path_with_existence() keeps the existence marker vocabulary consistent between --help and config path.
  • Read-only guarantee for config path is regression-tested (run_path_does_not_create_file).
  • No-home-directory case is handled with a clear inline message ((no config path resolvable — set $HOME or $XDG_CONFIG_HOME)).

Files changed

  • src/cli.rs — dynamic after_help builder; reworded --config doc.
  • src/cli_config.rs — new ConfigAction::Path(ConfigPathArgs).
  • src/config_cmd/mod.rs + src/config_cmd/path.rs — read-only runner with text + JSON output.
  • src/common/paths.rs — shared existence-marker formatter.
  • src/main.rs — parse via Cli::from_arg_matches after runtime composition.
  • docs/man/all-smi.1config subcommand in COMMANDS; per-platform paths in FILES; ENERGY ACCOUNTING points at config path.
  • README.mdconfig path helper entry; tightened --config wording.
  • tests/config_path_help_test.rs (integration) + inline unit tests in paths.rs, cli.rs, config_cmd/path.rs.

Test plan

  • cargo fmt --check
  • cargo clippy --lib --tests -- -D warnings
  • cargo test --test config_path_help_test (7 new integration tests)
  • cargo test --lib common::paths::tests (3 new + 7 existing pass)
  • cargo test --bin all-smi config_cmd::path (6 new tests pass)
  • cargo test --bin all-smi cli::tests (3 new + 5 existing pass)
  • cargo test --bin all-smi config_cmd (existing render tests still pass)
  • cargo test --test config_file_integration_test (existing 14 tests still pass)
  • Manual: ./target/debug/all-smi --help shows Configuration file + Energy Session blocks
  • Manual: ./target/debug/all-smi config path prints active path + search order
  • Manual: ./target/debug/all-smi config path --json emits stable JSON schema
  • Manual: confirmed config path does NOT create the file (no ~/.config/all-smi/ after invocation; no /tmp/explicit_nope.toml after --config override)
  • Manual: groff -Tutf8 -man docs/man/all-smi.1 renders cleanly; new FILES entries display correctly

… subcommand

Resolves a discoverability gap reported by an external user: `all-smi
--help` did not reveal where the TOML config file lives, and the only
pointer (`--config <PATH>`'s flag doc) redirected to `config init`, a
side-effecting command that writes a file.

Changes:

* `src/cli.rs` — compose `after_help` at runtime via
  `build_command_with_runtime_help()` so the resolved per-user config
  path (honouring `$HOME` / `$XDG_CONFIG_HOME` / `%APPDATA%`) can be
  injected into `--help`. New `config_help_block()` renders a short
  "Configuration file" section with the active path plus an
  `(active)` / `(not found)` marker. Reword `--config <PATH>` doc to
  point at the read-only discovery path instead of `config init`.
* `src/main.rs` — parse via `Cli::from_arg_matches` so the runtime help
  surface reaches `--help` / `-h`.
* `src/cli_config.rs` — add `ConfigAction::Path(ConfigPathArgs)` with
  `--json` for scripts.
* `src/config_cmd/path.rs` — new strictly-read-only runner. Prints the
  active path and ordered search list; supports `--json` with a stable
  schema (`active`, `exists`, `overridden`, `search_order`). Honours
  `--config <PATH>` by reporting the override and suppressing the
  candidate list. Never opens a file for write — regression-guarded by
  a unit test.
* `src/common/paths.rs` — shared `format_path_with_existence()` helper
  used by both the help block and the `config path` runner so the
  marker vocabulary stays consistent. Degrades gracefully when no home
  directory is resolvable.
* `docs/man/all-smi.1` — add `config` subcommand to COMMANDS, enumerate
  per-platform `config.toml` paths in FILES, and point ENERGY
  ACCOUNTING at the new `config path` rather than `config init`.
* `README.md` — add `config path` to the helpers list and tighten the
  `--config` flag wording to mention the read-only discovery surface.
* `tests/config_path_help_test.rs` + inline unit tests — assert the
  Configuration file block renders in `--help`, the Energy Session
  block survives the runtime composition, the existence marker is
  present, the `--config` flag help no longer only redirects to a
  side-effecting command, and the new `config path` subcommand
  (including `--json`) parses cleanly through the runtime-composed
  command tree.

Acceptance criteria (issue #213):
- `--help` / `-h` show the active config path with an existence marker
- The displayed path matches `paths::default_config_path()`
- The block points to `config init`, `config print`, and `--config`
- `all-smi config path` is read-only and never creates a file
- Man page `FILES` documents per-platform `config.toml` locations
- No-home-directory case degrades gracefully with a clear message
- Tests cover the help block and the new command; `cargo fmt --check`
  and `cargo clippy --lib --tests -- -D warnings` pass

Closes #213
@inureyes inureyes added type:enhancement New feature or request priority:medium Medium priority issue status:review Under review status:done Completed and removed status:review Under review labels May 24, 2026
@inureyes inureyes merged commit a094d4a into main May 24, 2026
4 checks passed
@inureyes inureyes deleted the feat/issue-213-config-path-help branch May 24, 2026 06:38
@inureyes inureyes self-assigned this May 24, 2026
inureyes added a commit that referenced this pull request May 24, 2026
Refs #221, #222, #224, #225, #226, #227.

Align config path active discovery with the implicit loader's first-existing-candidate semantics, correct record output help and resolver docs against the binary default, and make the swap-color regression test derive crossterm's current Red SGR sequence instead of hard-coding older encodings.
inureyes added a commit that referenced this pull request May 24, 2026
Refs #221, #222, #224, #225, #226, #227.

Align config path active discovery with the implicit loader's first-existing-candidate semantics, correct record output help and resolver docs against the binary default, and make the swap-color regression test derive crossterm's current Red SGR sequence instead of hard-coding older encodings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority issue status:done Completed type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surface the active TOML config file location in --help (and add a side-effect-free config path lookup)

1 participant