ink-command-router
v1.0.0
Published
A simple React based router for ink CLIs.
Downloads
4
Maintainers
Readme
ink-command-router
A simple React based router for ink CLI commands.
Getting started
Install the package.
yarn add ink-command-router
Configure your commands.
import { Text, render } from "ink";
import { CommandRouter, Command, NoMatch, useArgs } from "ink-command-router";
const Help = () => {
return <Text>I should probably tell you how to use this tool... 😅</Text>;
};
const Version = () => {
return <Text>1.0.0</Text>;
};
const PrintParsedArgs = () => {
const args = useArgs();
return <Text>{JSON.stringify(args, null, 2)}</Text>;
};
const App = () => {
return (
<CommandRouter args={process.argv}>
<Command name="help">
<Help />
</Command>
<Command name="version">
<Version />
</Command>
<Command name="print-parsed-args">
<PrintParsedArgs />
</Command>
<NoMatch>
<Help />
</NoMatch>
</CommandRouter>
);
};
render(<App />);
You can then use the tool like so:
> tool help
> I should probably tell you how to use this tool... 😅
>
> tool version
> 1.0.0
>
> tool print-parsed-args -hello world -foo=bar --one=two --three four final-arg
> {
> "_": ["final-arg"],
> "hello":"world",
> "one":"two",
> "three":"four"
> }
>
> tool this-does-not-exist
> I should probably tell you how to use this tool... 😅