DEV Community

Cover image for CLI parser for Ink js
souvik
souvik

Posted on

CLI parser for Ink js

I recently stumbled upon ink, and really liked it. Ink provides the same component-based UI building experience that React offers in the browser, but for command-line apps.

for CLI parsing we can use any libraries out there, but all the libraries accept string for the help text. I really wanted a library that would be light and also help render ink components, so as to leverage the beautiful ink library. So I am currently working on https://github.com/Souvikns/ink-cli-parser where users can pass ink component is a help string.

import parser from './index';
import React, { FC } from 'react';
import { Text, Newline } from 'ink';

const Help: FC<any> = () => {

    return <>

        <Text backgroundColor="greenBright" bold color="white" > USAGE </Text>
        <Newline />
        <Text>$ cli-command {"<command>"} [options]</Text>
        <Newline />
        <Text backgroundColor="cyanBright" bold color="white" > COMMANDS </Text>
        <Newline />
        <Text><Text color="cyanBright">new</Text> creates a new file</Text>
        <Text><Text color="cyanBright">duplicate</Text> duplicates a existing file</Text>
        <Newline />
        <Text backgroundColor="yellowBright" bold color="black" > OPTIONS </Text>
        <Newline />
        <Text><Text color="yellowBright">--random</Text> prints random data</Text>

    </>
}

let cli = parser(Help);

console.log(cli)
// {inputs: [], flags: {h: true}}

Enter fullscreen mode Exit fullscreen mode

Do check it out any thoughts are welcomed.

Latest comments (0)