diff --git a/scripts/install-core.js b/scripts/install-core.js index b01f039..ec6cfed 100755 --- a/scripts/install-core.js +++ b/scripts/install-core.js @@ -406,6 +406,7 @@ function parseArgs(argv) { check: false, profileIds: null, help: false, + version: false, verbose: false, quiet: false, }; @@ -447,6 +448,11 @@ function parseArgs(argv) { continue; } + if (arg === "--version" || arg === "-v") { + options.version = true; + continue; + } + if (arg === "--verbose") { options.verbose = true; continue; diff --git a/scripts/install.js b/scripts/install.js index 55e356b..9bb54bc 100755 --- a/scripts/install.js +++ b/scripts/install.js @@ -4,6 +4,7 @@ const fs = require("fs"); const readline = require("readline/promises"); +const { version } = require("../package.json"); const { buildInspectionCache, getDefaultRepoRoot, @@ -178,12 +179,19 @@ async function runPlainInstaller({ profiles, options, initialSelectedIds, source } async function main(argv) { - const config = loadConfig(getDefaultRepoRoot()); - const { configError, sourceRoot } = config; - if (sourceRoot && !fs.existsSync(sourceRoot)) { - process.stderr.write(`Warning: source root ${sourceRoot} does not exist. Profiles may be empty.\n`); - } - if (configError) { + const options = parseArgs(argv); + + if (options.version) { + console.log(version); + return; + } + + const config = loadConfig(getDefaultRepoRoot()); + const { configError, sourceRoot } = config; + if (sourceRoot && !fs.existsSync(sourceRoot)) { + process.stderr.write(`Warning: source root ${sourceRoot} does not exist. Profiles may be empty.\n`); + } + if (configError) { const choice = await handleInvalidConfig(configError); if (choice === "exit") { process.exit(0); @@ -197,7 +205,6 @@ async function main(argv) { const detection = detectInstalledTools(); const profiles = discoverProfiles(undefined, detection); - const options = parseArgs(argv); if (options.help) { printUsage(profiles); diff --git a/tests/install-core.test.js b/tests/install-core.test.js index 613c53c..f1fd0ee 100644 --- a/tests/install-core.test.js +++ b/tests/install-core.test.js @@ -120,6 +120,7 @@ describe("parseArgs", () => { assert.strictEqual(opts.selectAll, false); assert.strictEqual(opts.listOnly, false); assert.strictEqual(opts.help, false); + assert.strictEqual(opts.version, false); assert.strictEqual(opts.profileIds, null); assert.strictEqual(opts.verbose, false); assert.strictEqual(opts.quiet, false); @@ -149,6 +150,14 @@ describe("parseArgs", () => { assert.strictEqual(core.parseArgs(["-h"]).help, true); }); + it("--version sets version", () => { + assert.strictEqual(core.parseArgs(["--version"]).version, true); + }); + + it("-v sets version", () => { + assert.strictEqual(core.parseArgs(["-v"]).version, true); + }); + it("'sync' subcommand is silently ignored", () => { const opts = core.parseArgs(["sync", "--dry-run"]); assert.strictEqual(opts.dryRun, true);