From a0025938d37640338a259f7ca3fecf55c81e83de Mon Sep 17 00:00:00 2001 From: yaegassy Date: Sat, 2 Jul 2022 00:43:44 +0900 Subject: [PATCH] Add --version flag for ansible-language-server (#392) * feat: add --version flag for ansible-language-server * chore: add test for --version flag in ALS --- bin/ansible-language-server | 7 ++++++- test/utils/runCommand.test.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/ansible-language-server b/bin/ansible-language-server index 0d646de3..e503bab0 100755 --- a/bin/ansible-language-server +++ b/bin/ansible-language-server @@ -1,3 +1,8 @@ #!/usr/bin/env node -require("../out/server/src/server.js"); +if (process.argv.includes("--version")) { + const pkgJSON = require("../package.json"); + console.log(`${pkgJSON["version"]}`); +} else { + require("../out/server/src/server.js"); +} diff --git a/test/utils/runCommand.test.ts b/test/utils/runCommand.test.ts index b6d72fe3..2ff8f3d3 100644 --- a/test/utils/runCommand.test.ts +++ b/test/utils/runCommand.test.ts @@ -3,9 +3,26 @@ import { AssertionError, expect } from "chai"; import { WorkspaceManager } from "../../src/services/workspaceManager"; import { createConnection } from "vscode-languageserver/node"; import { getDoc } from "../helper"; +import * as path from "path"; describe("commandRunner", () => { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const pkgJSON = require(path.resolve(__dirname, "..", "..", "package.json")); + const tests = [ + { + args: [ + path.join( + path.resolve(__dirname, "..", ".."), + "bin", + "ansible-language-server" + ), + "--version", + ], + rc: 0, + stdout: `${pkgJSON["version"]}`, + stderr: "", + }, { args: ["ansible-config", "dump"], rc: 0,