Skip to content

Commit

Permalink
feat: adding a --version command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopheBougere committed Jun 6, 2023
1 parent 5372e3a commit 4efbaaf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Please provide a complete state machine definition:
A clear and concise description of what you expected to happen.

**Version:**
Can be found by running `asl-validator --version`.

**Additional context**
Add any other context about the problem here.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Usage: asl-validator [options]
Amazon States Language validator

Options:
-V, --version output the version number
--json-definition <jsonDefinition> JSON definition (default: [])
--json-path <jsonPath> JSON path (default: [])
--yaml-definition <yamlDefinition> YAML definition (default: [])
Expand Down
19 changes: 19 additions & 0 deletions bin/asl-validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

import fs from "fs";
import path from "path";
import { program } from "commander";
import YAML from "yaml";

Expand All @@ -21,8 +22,26 @@ function collect(value: string, previous: string[]) {
return previous.concat([value]);
}

function getVersion(packageJsonPath: string): string | null {
if (!fs.existsSync(packageJsonPath)) {
return null;
}
const { version } = JSON.parse(
fs.readFileSync(packageJsonPath).toString()
) as {
version: string;
};
return version;
}

program
.description("Amazon States Language validator")
// make it work wether it is compiled or not
.version(
getVersion(path.join(__dirname, "../package.json")) ??
getVersion(path.join(__dirname, "../../package.json")) ??
""
)
.option("--json-definition <jsonDefinition>", "JSON definition", collect, [])
.option("--json-path <jsonPath>", "JSON path", collect, [])
.option("--yaml-definition <yamlDefinition>", "YAML definition", collect, [])
Expand Down

0 comments on commit 4efbaaf

Please sign in to comment.