feat(config): add config path command
Description
The global configuration location varies by platform, and by whether a
legacy ~/.config/glab-cli directory exists:
$GLAB_CONFIG_DIRwhen set.~/.config/glab-cliwhen that directory already holds aconfig.yml.- Otherwise
$XDG_CONFIG_HOME/glab-cli— on macOS,~/Library/Application Support/glab-cli.
There was no way to resolve that from the CLI, so users and tooling had to reimplement the lookup or guess. That matters when granting a sandbox write access to the file, when pointing an editor at it, and when reporting bugs.
glab config path prints the resolved file; --dir prints the containing
directory. --dir exists because a write creates a temporary file in the
directory and renames it over config.yml, so anything granting write
access needs the directory, not just the file.
Output goes to stdout so it composes:
$EDITOR "$(glab config path)"The path is reported whether or not the file exists yet, so it works
before the first glab auth login.
Related Issues
Came out of investigating #8262 (closed) (sandboxed glab usage), but it stands on
its own and does not resolve that issue.
How has this been tested?
Four tests via cmdtest.SetupCmdForTest, covering the default output, the
--dir branch, a not-yet-created config file, and argument rejection
(cobra.NoArgs).
Manually, against a real config:
$ glab config path
/Users/USERNAME/.config/glab-cli/config.yml
$ glab config path --dir
/Users/USERNAME/.config/glab-cli
$ GLAB_CONFIG_DIR=/tmp/whatever glab config path
/tmp/whatever/config.ymlmake gen-docs run and the generated pages committed. Help output checked
at a narrow terminal width to confirm the Long paragraphs reflow without
orphan fragments.