diff --git a/docs/getting-started.md b/docs/getting-started.md index beccdc0b..1e4c9cd6 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -27,6 +27,8 @@ Verify the installation: apiops --version ``` +The short flags `-v` and `-V` also print the installed CLI version. + --- ## 1. Extract APIM Configuration diff --git a/src/cli/index.ts b/src/cli/index.ts index 71f8a66a..e0682b40 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -21,6 +21,7 @@ const program = new Command(); program .name('apiops') .version(packageJson.version) + .version(packageJson.version, '-v') .description('CLI tool for Azure API Management configuration-as-code'); // Show global options in subcommand help (e.g. apiops extract --help) diff --git a/tests/unit/cli/index.test.ts b/tests/unit/cli/index.test.ts index 233c5cda..ad5ab297 100644 --- a/tests/unit/cli/index.test.ts +++ b/tests/unit/cli/index.test.ts @@ -33,15 +33,18 @@ async function getPackageVersion(): Promise { } describe('CLI entry point', () => { - it('should display version with --version', async () => { - const [result, expectedVersion] = await Promise.all([runCli(['--version']), getPackageVersion()]); + it.each(['--version', '-V', '-v'])('should display version with %s', async (flag) => { + const [result, expectedVersion] = await Promise.all([runCli([flag]), getPackageVersion()]); expect(result.stdout.trim()).toBe(expectedVersion); + expect(result.stderr).toBe(''); expect(result.exitCode).toBe(0); }, 15_000); it('should display help with --help', async () => { const result = await runCli(['--help']); expect(result.stdout).toContain('apiops'); + expect(result.stdout).toContain('-V, --version'); + expect(result.stdout).toMatch(/-v\s+output the version number/); expect(result.stdout).toContain('--log-level'); expect(result.stdout).toContain('--format'); expect(result.stdout).toContain('--subscription-id');