1.1.0 • Published 1 year ago

ink-navigation v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

ink-navigation

A simple React based router for ink CLI commands.

Getting started

Install the package:

npm install ink-navigation

or

yarn add ink-navigation

Configure your commands.

#!/usr/bin/env node
import React from 'react';
import { Text, render } from 'ink';
import { CommandRouter, Command, NoMatch, useArgs } from 'ink-navigation';

const Help = () => {
  return <Text>Add a description of the help...</Text>;
};

const Version = () => {
  return <Text>1.0.0</Text>;
};

const ParsedArgs = () => {
  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="parsed-args">
        <ParsedArgs />
      </Command>
      <NoMatch>
        <Help />
      </NoMatch>
    </CommandRouter>
  );
};

render(<App />);

You can then use the tool like so:

> tool help
> Add a description of the help...
>
> tool version
> 1.0.0
>
> tool parsed-args -hello world -foo=bar --one=two --three four final-arg
> {
>   "_": ["final-arg"],
>   "hello":"world",
>   "foo": "bar",
>   "one":"two",
>   "three":"four"
> }
>
> tool this-does-not-exist
> Add a description of the help...

Argument parsing

Arguments are parsed using minimist.