Repository
Current version released
4 years ago
Dependencies
deno.land/x
Deno Args
Extensible CLI arguments parser for Deno with intelligent TypeScript inference.
⚠ Warning: This project is in an early stage of development. Things may break without notice. Be sure to specify exact version when use.
Usage Examples
import args from 'https://deno.land/x/args/wrapper.ts'
import { HelpFlag, Option } from 'https://deno.land/x/args/argument-types.ts'
import { FiniteNumber, Choice } from 'https://deno.land/x/args/value-types.ts'
const parser = args
.with(EarlyExitFlag('help', {
describe: 'Show help',
exit () {
console.log(parser.help())
return Deno.exit()
}
}))
.with(Option('a', {
type: FiniteNumber,
describe: 'Value of a'
}))
.with(Option('b', {
type: FiniteNumber,
describe: 'Value of b'
}))
.with(Option('operator', {
type: Choice<'add' | 'sub'>(
{
value: 'add',
describe: 'Add two numbers'
},
{
value: 'sub',
describe: 'Subtract two numbers'
}
),
alias: ['o'],
describe: 'Operator to use'
}))
const res = parser.parse(Deno.args)
if (res.error) {
console.error('Failed to parse CLI arguments')
for (const e of res.error) {
console.error(e.toString)
}
Deno.exit(1)
} else {
const { a, b, operator } = res.value
switch (operator) {
case 'add':
console.log(a + b)
case 'sub':
console.log(a - b)
}
}
TODO
- Report multiple errors at the same time
- Improve help
- Implement as
EarlyExit
-
Support both flag and subcommand ((Do it manually)--help
andhelp
) - Help for subcommand: (
prog cmd --help
andprog help cmd
) - Proper indentation
- Categories
- Reference clap’s
- Implement as
- Use a task runner
- Negative numbers
- Optional flags
- Sharing flags between subcommands
-
index.ts
- Copy
README.md
tolib
- Wait for task runner
- Integration with
@tsfun/pipe
- TSDoc
- Describe all public APIs
- Add examples to
flag-types.ts
- Add examples to
wrapper.ts
- Support subcommands
- Known subcommands (subcommands that are known and defined by the programmer)
- Unknown subcommands (e.g.
git foo
will findgit-foo
and execute it)
-
Release for Node.js(Blocker: https://github.com/denoland/deno/issues/4538, https://github.com/denoland/deno/issues/4539, https://github.com/denoland/deno/issues/4542) - Add CI
- GitHub actions
- Travis CI
- Test
-
Use(Blocker: https://github.com/denoland/deno/issues/4538, https://github.com/denoland/deno/issues/4539, https://github.com/denoland/deno/issues/4542)jest
(Deno test ecosystem is yet matured) -
Use(No needs)jest
to snapshotpreview
- Use
deno test
to make some assertions
-
- Use
prettier
to format - Type test
- When all is done, remove warning