Skip to content

Commit f3b1533

Browse files
committed
1.2.8
- Fix CLI argument parsing - Fix CLI crashing on use
1 parent 1b002f2 commit f3b1533

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env node
2-
require('../dist/src/cli.js');
2+
require('../dist/cli.js');

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.2.8
4+
*2021-10-03*
5+
- Changed CLI arguments `--help` and `--version` to override other arguments.
6+
- Fixed CLI argument `--version` not returning the current version.
7+
- Fixed command-line usage not working.
8+
39
## 1.2.7
410
*2021-10-03*
511
- Fixed snapshots appearing malformed when using `getVersions()`.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "pack-format",
3-
"version": "1.2.7",
3+
"version": "1.2.8",
44
"description": "Returns the pack_format of any Minecraft version, including snapshots",
55
"scripts": {
66
"prepublish": "tsc",
7-
"test": "tsc && node dist/test/test"
7+
"test": "tsc && node test/test"
88
},
99
"keywords": [
1010
"minecraft",
@@ -14,13 +14,13 @@
1414
"data pack",
1515
"pack format"
1616
],
17-
"main": "dist/src/index.js",
17+
"main": "dist/index.js",
1818
"bin": {
1919
"pack-format": "bin/index.js"
2020
},
2121
"files": [
2222
"bin/",
23-
"dist/src/"
23+
"dist/"
2424
],
2525
"engines": {
2626
"node": ">=12"

src/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ const args = {
1919
latest: rawArgs.some(arg => /^-+L|^-+latest/.test(arg)),
2020
_: rawArgs.filter(arg => !arg.startsWith('-')),
2121
}
22-
const ver = args._[0]
22+
const ver = !args.help && !args.version && args._[0]
2323

2424
if (ver) {
25-
if (args.version) {
26-
console.log(`pack-format v${VERSION}`)
27-
}
28-
else if (args.list) {
25+
if (args.list) {
2926
if (Number.isNaN(ver)) console.error(`'${ver}' is not a valid pack format`)
3027
else if (Math.round(+ver) !== +ver) console.error(`'${ver}' is a version number, not a pack format`)
3128
else {
@@ -45,6 +42,9 @@ else if (args.latest) {
4542
if (type) console.log(`The latest ${type} pack format version is ${LATEST[type]}.`)
4643
else console.log(`The latest pack format version is ${Math.max(LATEST.resource, LATEST.data)}.`)
4744
}
45+
else if (args.version) {
46+
console.log(`pack-format ${VERSION}`)
47+
}
4848
if (args.help) {
4949
console.log(`\n${indent(1)}pack-format arguments:`)
5050
log(

test/test.ts renamed to test/test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { getPackFormat as packFormat, getVersions } from '../src/index'
2-
import { PackType, FormatResult, VersionsResult } from '../src/types'
1+
const { getPackFormat: packFormat, getVersions } = require('../dist/index')
32

4-
let [total, passed, failed]: number[] = [0, 0, 0]
3+
let [total, passed, failed] = [0, 0, 0]
54

6-
function testPackFormat([input, type]: [string, PackType?], expected: FormatResult): void {
7-
let ver: FormatResult = packFormat(input, type)
8-
let pass: boolean = ver === expected
5+
function testPackFormat([input, type], expected) {
6+
const ver = packFormat(input, type)
7+
const pass = ver === expected
98
if (pass) passed++
109
else failed++
1110
total++
@@ -17,13 +16,13 @@ function testPackFormat([input, type]: [string, PackType?], expected: FormatResu
1716
)
1817
}
1918

20-
function testVersions([input, type]: [number, PackType?], expected: VersionsResult) {
21-
let obj: VersionsResult = getVersions(input, type)
19+
function testVersions([input, type], expected) {
20+
const obj = getVersions(input, type)
2221
let pass = obj.releases.max === expected.releases.max && obj.snapshots.min === expected.snapshots.min
2322
if (pass) passed++
2423
else failed++
2524
total++
26-
const cleanObj = (obj: VersionsResult) => JSON.stringify(obj).replace(/"([^"]*?)":/g, '$1:')
25+
const cleanObj = (obj) => JSON.stringify(obj).replace(/"([^"]*?)":/g, '$1:')
2726
console.log(
2827
(pass ? ' ' : '! ')
2928
+ `Versions with ${type ? type + ' ' : ''}pack format ${input}: ${cleanObj(obj)}`

0 commit comments

Comments
 (0)