https://github.com/crqrdotcom/cmdr
A simple module to parse CLI arguments, flags and options for Deno.
https://github.com/crqrdotcom/cmdr
cli cli-parser command-line command-line-parser deno
Last synced: about 2 months ago
JSON representation
A simple module to parse CLI arguments, flags and options for Deno.
- Host: GitHub
- URL: https://github.com/crqrdotcom/cmdr
- Owner: crqrdotcom
- License: mit
- Created: 2021-03-31T13:36:08.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-31T14:06:30.000Z (almost 5 years ago)
- Last Synced: 2025-12-02T02:10:17.120Z (about 2 months ago)
- Topics: cli, cli-parser, command-line, command-line-parser, deno
- Language: TypeScript
- Homepage: https://deno.land/x/cmdr
- Size: 3.91 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# cmdr
> A simple module to parse CLI arguments, flags and options for [Deno](https://deno.land).
### Goals
- Simple to use
- Easy configuration
- Arguments validation (*todo*)
- Auto-generated manual (*todo*)
***NOTE:** expect it to break before `1.0.0` release.*
## Getting Started
```typescript
import { cmdr } from "https://deno.land/x/cmdr/mod.ts";
type Options = { name: string; help: boolean };
const { usage, match } cmdr("hello-world -h, --help");
if (match.help) {
console.info(usage.string);
Deno.exit(0);
}
console.info(`Hello, ${match.name ? match.name : 'you there'}!`);
```
## Example
Check more exaples [here](/examples).
```typescript
// main.ts
import { cmdr } from "https://deno.land/x/cmdr/mod.ts";
const { usage, match } = cmdr(
"hello-world ... -q, --question= -v, --version -h, --help",
)(Deno.args);
if (match.help) {
console.info(usage.string);
Deno.exit(0)
}
if (match.version) {
console.log("Version: 0.0.0");
Deno.exit(0);
}
if (match.name.length === 0) {
console.error("Please, specify at least one ")
Deno.exit(1);
}
const namesCombined = match.name.join(", ").replace(
`, ${match.name[match.name.length - 1]}`,
` and ${match.name[match.name.length - 1]}`,
);
console.log(`Hello, ${namesCombined}!`);
if (match.question) {
console.log(`Here's a question: ${match.question}`)
}
```
### Running the example
```bash
$ deno run ./main.ts -q "what do you want for dinner?" John Alice Joe
# Hello, John, Alice and Joe!
# Here's a question: what do you want for dinner?
```
### Compiling the example
```bash
$ deno compile --unstable --lite -o hello_world ./main.ts
# ...
$ ./hello_world -q "what do you want for dinner?" John Alice Joe
# Hello, John, Alice and Joe!
# Here's a question: what do you want for dinner?
```
## Contributing
All contributions are very welcome!
If you find any bug or have a feature request, please [open a new issue](https://github.com/crqra/cmdr/issues).
For code or documentation contributions, [fork this repository](https://github.com/crqra/cmdr/fork), do your thing, and submit a [Pull Request](https://github.com/crqra/cmdr/pulls).
## License
This project is released under the [MIT License](/LICENSE).