generated from napi-rs/package-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(resolver): fix types and rewrite value parser * chore(watch): build debug version in watch script * chore(changeset): bump version * feat(parser): refactor arguments parser * test: add and update test samples * ci(test): add examples building
- Loading branch information
Showing
19 changed files
with
374 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': patch | ||
--- | ||
|
||
Fix context args annotations to `Record<string, any>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': minor | ||
--- | ||
|
||
Refactor arguments parsing policy and support global options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': patch | ||
--- | ||
|
||
Refactor merge arguments matches policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': patch | ||
--- | ||
|
||
Remove `{ length: 1}` annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': patch | ||
--- | ||
|
||
Refactor `Vec<String>` to `Vec<&str>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'archons': patch | ||
--- | ||
|
||
Improve parser resolver and determine default parser by action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
import test from 'ava' | ||
import { spawnSync } from 'child_process' | ||
|
||
import { Command, defineCommand, run } from '../index' | ||
|
||
test('define command', (t) => { | ||
const cmd: Command = { | ||
meta: { | ||
name: 'test', | ||
version: '1.0.0', | ||
about: 'test command', | ||
}, | ||
options: { | ||
foo: { | ||
type: 'positional', | ||
}, | ||
}, | ||
callback: (ctx: any) => { | ||
console.log(ctx) | ||
const cmd: Command = { | ||
meta: { | ||
name: 'test', | ||
version: '1.0.0', | ||
about: 'test command', | ||
}, | ||
options: { | ||
foo: { | ||
type: 'positional', | ||
action: 'set', | ||
}, | ||
} | ||
}, | ||
callback: (_: any) => {}, | ||
} | ||
|
||
const main = defineCommand(cmd) | ||
|
||
test('define command', (t) => { | ||
t.deepEqual(defineCommand(cmd), cmd) | ||
}) | ||
|
||
test('run command', (t) => { | ||
t.notThrows(() => { | ||
run(main, ['node', 'test.js']) | ||
}) | ||
}) | ||
|
||
test('run help', (t) => { | ||
const result = spawnSync('node', [`examples/simple.cjs`, '--help']) | ||
t.is(result.error, undefined) | ||
t.is(result.stderr.length, 0) | ||
t.deepEqual(result.status ?? 0, 0) | ||
}) | ||
|
||
test('run version', (t) => { | ||
const version = spawnSync('node', [`examples/simple.cjs`, '--version']) | ||
const no_version = spawnSync('node', [`examples/no_version.cjs`, '--version']) | ||
t.is(version.error, undefined) | ||
t.is(version.stderr.length, 0) | ||
t.deepEqual(version.status ?? 0, 0) | ||
t.not(no_version.stderr.length, 0) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import test from 'ava' | ||
import { spawnSync } from 'child_process' | ||
|
||
import { Context, defineCommand, run } from '../index' | ||
|
||
test('positional option', (t) => { | ||
const main = defineCommand({ | ||
meta: { | ||
name: 'test', | ||
}, | ||
options: { | ||
foo: { | ||
type: 'positional', | ||
}, | ||
}, | ||
callback: (ctx: Context) => { | ||
t.is(ctx.args.foo, 'foo') | ||
}, | ||
}) | ||
t.notThrows(() => { | ||
run(main, ['node', 'test.js', 'foo']) | ||
}) | ||
}) | ||
|
||
test('required positional option', (t) => { | ||
const result = spawnSync('node', [`examples/positional_required.cjs`, 'foo']) | ||
const should_fail = spawnSync('node', [`examples/positional_required.cjs`]) | ||
t.is(result.error, undefined) | ||
t.is(result.stderr.length, 0) | ||
t.deepEqual(result.status ?? 0, 0) | ||
t.not(should_fail.stderr.length, 0) | ||
}) | ||
|
||
test('boolean flag', (t) => { | ||
const main = defineCommand({ | ||
meta: { | ||
name: 'test', | ||
}, | ||
options: { | ||
verbose: { | ||
type: 'option', | ||
action: 'store', | ||
}, | ||
eq: { | ||
type: 'option', | ||
action: 'store', | ||
alias: ['e'], | ||
}, | ||
}, | ||
callback: (ctx: Context) => { | ||
t.is(ctx.args.verbose, ctx.args.eq) | ||
}, | ||
}) | ||
t.notThrows(() => { | ||
run(main, ['node', 'test.js', '--verbose', '-e']) | ||
}) | ||
t.notThrows(() => { | ||
run(main, ['node', 'test.js']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import test from 'ava' | ||
|
||
import { Context, defineCommand, run } from '../index' | ||
|
||
test('sub command', (t) => { | ||
const cmd = defineCommand({ | ||
meta: {}, | ||
options: { | ||
foo: { | ||
type: 'positional', | ||
}, | ||
}, | ||
callback: (ctx: Context) => { | ||
t.deepEqual(ctx.args, { foo: 'foo' }) | ||
}, | ||
}) | ||
const main = defineCommand({ | ||
meta: { | ||
name: 'test', | ||
}, | ||
options: {}, | ||
subcommands: { | ||
cmd, | ||
}, | ||
}) | ||
t.notThrows(() => { | ||
run(main, ['node.exe', 'test.js', 'cmd', 'foo']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineCommand, run, type Context } from '../index' | ||
|
||
const main = defineCommand({ | ||
meta: { | ||
name: 'simple', | ||
}, | ||
options: {}, | ||
callback: (_: Context) => {}, | ||
}) | ||
|
||
run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Context, defineCommand, run } from '..' | ||
|
||
const main = defineCommand({ | ||
meta: { | ||
name: 'test', | ||
}, | ||
options: { | ||
foo: { | ||
type: 'positional', | ||
required: true, | ||
}, | ||
}, | ||
callback: (_: Context) => {}, | ||
}) | ||
|
||
run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.