Add --version option
Change-Id: I4390f2df5a7e0c61c6f8a5233e5092f9f907435e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe73e83..045a16a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
### Added
- Hashtag tagging with the `HST` tag.
+- CLI version output via `-V` / `--version`.
- Regression tests for hashtag tagging and `ADR` tagging behavior.
- Expanded documentation covering the tagset, CoNLL-U output examples, limitations, performance, and application contexts.
diff --git a/Readme.md b/Readme.md
index d92838a..1aff8f2 100644
--- a/Readme.md
+++ b/Readme.md
@@ -69,12 +69,18 @@
```shell
cat ./test/data/ndy.conllu | npx conllu2cmc
+
+# Show version
+npx conllu2cmc -V
```
### Using standalone binary
```shell
cat ./test/data/ndy.conllu | ./bin/linux/conllu2cmc
+
+# Show version
+./bin/linux/conllu2cmc -V
```
### Generate KorAP-XML zip with CMC annotations
@@ -98,6 +104,9 @@
# Show help
docker run --rm korap/conllu-cmc --help
+
+# Show version
+docker run --rm korap/conllu-cmc -V
```
## Performance
diff --git a/src/index.js b/src/index.js
index f8e16f9..348a9a7 100755
--- a/src/index.js
+++ b/src/index.js
@@ -1,5 +1,7 @@
#!/usr/bin/env node
+const packageVersion = require('../package.json').version;
+
const emoticonRegex = /^(\:\w+\:|\<[\/\\]?3|[\(\)\\\D|\*\$][\-\^]?[\:\;\=]|[\:\;\=B8][\-\^]?[3DOPp\@\$\*\\\)\(\/\|])(?=\s|[\!\.\?]|$)/;
const hashtagRegex = /^#(?=.*\p{L})[\p{L}\p{M}\p{N}]+$/u;
const urlRegex = /^(ftp|http)s?:\/\/[^\s]+/;
@@ -33,6 +35,7 @@
const optionDefinitions = [
{ name: 'sparse', alias: 's', type: Boolean, description: 'Print only the files, lines that have POS annotations.' },
+ { name: 'version', alias: 'V', type: Boolean, description: 'Print the current package version.' },
{ name: 'help', alias: 'h', type: Boolean, description: 'Print this usage guide.' },
]
@@ -43,7 +46,7 @@
},
{
header: 'Synopsis',
- content: '$ conllu-cmc [-s] < input.conllu > output.conllu'
+ content: '$ conllu-cmc [-s] < input.conllu > output.conllu\n$ conllu-cmc -V'
},
{
header: 'Options',
@@ -68,6 +71,11 @@
process.exit(0);
}
+if (options.version) {
+ console.log(packageVersion);
+ process.exit(0);
+}
+
const EmojiRegex = require('emoji-regex');
const emojiRegex = EmojiRegex();
const { once } = require('events');
diff --git a/test/test.js b/test/test.js
index 3014c90..fbf38e1 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,5 +1,6 @@
const { execSync } = require('child_process');
const exp = require('constants');
+const packageVersion = require('../package.json').version;
describe('conllu2cmc', () => {
test('Test sparse mode', (done) => {
@@ -45,6 +46,13 @@
done();
});
+ test('Test version flag', (done) => {
+ const stdout = execSync('node src/index.js -V').toString().trim();
+
+ expect(stdout).toBe(packageVersion);
+ done();
+ });
+
test('Regression test for hashtags: emit HST', (done) => {
const testInput = [
'# foundry = base',