fix: have version flag track package.json version

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-10-08 09:55:50 -07:00
parent 5b464d22e5
commit 492b12de40
2 changed files with 18 additions and 1 deletions
+2 -1
View File
@@ -9,13 +9,14 @@ import { Command } from "commander";
import bind from "./commands/bind.js";
import { action, supportedShells } from "./commands/root.js";
import { getVersion } from "./utils/version.js";
const program = new Command();
program
.name("inshellisense")
.description("IDE style command line auto complete")
.version("0.0.0", "-v, --version", "output the current version")
.version(await getVersion(), "-v, --version", "output the current version")
.option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
.option("-c, --command <commmand>", "command to use as initial input")
.option("--history", "get the last command execute")
+16
View File
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import url from "node:url";
import path from "node:path";
import fsAsync from "node:fs/promises";
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export const getVersion = async (): Promise<string> => {
const packageJsonPath = path.join(__dirname, "..", "..", "package.json");
const packageJson = await fsAsync.readFile(packageJsonPath, { encoding: "utf-8" });
const packageJsonParsed = JSON.parse(packageJson);
return packageJsonParsed.version;
};