feat(cli): codegraph version command + complete CLI Reference (#864)
* feat(cli): codegraph version command + complete CLI Reference Add a `codegraph version` subcommand plus the `-v` and `-version` spellings (commander already wires up `--version`/`-V`), so the version is easy to reach however a user guesses at it. The `-v`/`-version` forms are intercepted before commander parses — its version short flag is the capital `-V`, and its parser rejects a multi-character single-dash flag. A trailing `-v` on a subcommand still means `--verbose`. Document the previously-missing commands in the README CLI Reference: `daemon`/`daemons`, `unlock`, `telemetry`, `version`, and `help`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs(changelog): reference #864 on the version-command entry Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ff288ac711
commit
070ce4da2b
@@ -120,6 +120,18 @@ const packageJson = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8')
|
||||
);
|
||||
|
||||
// Make the version trivial to reach. commander's `.version()` (below) wires up
|
||||
// `--version` and `-V`; intercept the spellings it can't — lowercase `-v` and
|
||||
// single-dash `-version` — before any parsing. (commander's version short flag
|
||||
// is the capital `-V`, and its parser rejects a multi-character single-dash
|
||||
// flag.) The bare `codegraph version` subcommand is registered further down so
|
||||
// the affordance also shows up in `codegraph --help`.
|
||||
const firstArg = process.argv[2];
|
||||
if (firstArg === '-v' || firstArg === '-version') {
|
||||
console.log(packageJson.version);
|
||||
return;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// ANSI Color Helpers (avoid chalk ESM issues)
|
||||
// =============================================================================
|
||||
@@ -1978,6 +1990,21 @@ program
|
||||
process.exit(code);
|
||||
});
|
||||
|
||||
/**
|
||||
* codegraph version
|
||||
*
|
||||
* The bare-noun form of `--version`. commander already provides `--version`
|
||||
* and `-V`, and the `-v` / `-version` spellings are intercepted before parse
|
||||
* (see top of main). This subcommand makes `codegraph version` work and lists
|
||||
* the version affordance in `codegraph --help`.
|
||||
*/
|
||||
program
|
||||
.command('version')
|
||||
.description('Print the installed CodeGraph version (also: -v, --version)')
|
||||
.action(() => {
|
||||
console.log(packageJson.version);
|
||||
});
|
||||
|
||||
// Parse and run
|
||||
program.parse();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user