https://github.com/linbudulab/mustard
IoC & Native ES Decorator based command-line app builder.
https://github.com/linbudulab/mustard
Last synced: 2 months ago
JSON representation
IoC & Native ES Decorator based command-line app builder.
- Host: GitHub
- URL: https://github.com/linbudulab/mustard
- Owner: LinbuduLab
- License: mit
- Created: 2022-11-24T14:30:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-07T12:43:32.000Z (over 1 year ago)
- Last Synced: 2024-01-07T15:53:18.778Z (over 1 year ago)
- Language: TypeScript
- Homepage: https://mustard-cli.netlify.app/
- Size: 1.23 MB
- Stars: 37
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()



[](https://codecov.io/gh/LinbuduLab/Mustard)IoC & [Native ECMAScript Decorator](https://github.com/tc39/proposal-decorators) based command line app builder.
## Requires
- **Node.js >= 16.0.0**
- **TypeScript >= 5.0.0**## Features
- Born to be type safe
- Nest command support
- Validator support by [Zod](https://github.com/colinhacks/zod)
- Automatic usage info generation
- Build decoupled applications using IoC concepts
- Essential built-in utils for CLI app## Getting Started
- [Documentation](https://mustard-cli.netlify.app/)
```bash
$ pnpx create-mustard-app
```Sample with root command only:
```typescript
import { MustardFactory, MustardUtils } from "mustard-cli";
import { RootCommand, App, Input } from "mustard-cli/decorator";
import { CommandStruct, MustardApp } from "mustard-cli/cli";@RootCommand()
class RootCommandHandle implements CommandStruct {
@Input()
public name: string = "Harold";public run(): void {
console.log(`Hi, ${this.name}`);
}
}@App({
name: "hi",
commands: [RootCommandHandle],
})
class Project implements MustardApp {}MustardFactory.init(Project).start();
``````bash
$ hi
# Hi, Harold
$ hi John
# Hi, John
```Sample with root command and sub commands:
```typescript
import { MustardFactory } from "mustard-cli";
import {
Command,
RootCommand,
Option,
VariadicOption,
App,
Input,
} from "mustard-cli/decorator";
import { Validator } from "mustard-cli/validator";
import { CommandStruct, MustardApp } from "mustard-cli/cli";import path from "path";
@RootCommand()
class RootCommandHandle implements CommandStruct {
@Option("m")
public msg = "default value of msg";public run(): void {
console.log(`Root command executed with: msg: ${this.msg}`);
}
}@Command("update", "u", "update project dependencies")
class UpdateCommand implements CommandStruct {
@Option("depth", "depth of packages to update", Validator.Number().Gte(1))
public depth = 10;@Option(Validator.Boolean())
public dry = false;@Option({ name: "target", alias: "t" })
public targetOption: string;@Input()
public input: string[] = [];@VariadicOption()
public packages: string[] = [];public run(): void {
console.log(
`Update command executed with: depth: ${this.depth}, dry: ${
this.dry
}, targetOption: ${this.targetOption}, input: ${JSON.stringify(
this.input
)}, packages: ${JSON.stringify(this.packages)}`
);
}
}@App({
name: "mm",
commands: [RootCommandHandle, UpdateCommand],
configurations: {
allowUnknownOptions: true,
enableVersion: require(path.resolve("./package.json")).version,
},
})
class Project implements MustardApp {
onStart() {}onComplete() {}
}MustardFactory.init(Project).start();
``````bash
$ mm
# Root command executed with: msg: default value of msg
$ mm -m=hello
# Root command executed with: msg: hello
$ mm update
# Update command executed with: depth: 10, dry: false, targetOption: undefined, input: [], packages: []
$ mm update --depth=1 --target=dep --packages p1 p2 p3
# Update command executed with: depth: 1, dry: false, targetOption: dep, input: [], packages: ["p1","p2","p3"]
$ mm update p1 p2 p3 -t=dev
# Update command executed with: depth: 10, dry: false, targetOption: dev, input: ["p1","p2","p3"], packages: []
```## Samples
You can find more samples [Here](packages/sample/samples/).
## License
[MIT](LICENSE)