0.1.1-dev.0 • Published 3 years ago

oh-clif v0.1.1-dev.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Oh Clif!!

oh-clif is an object oriented cli framework intended for use with typescrypt (although it can also be used with pure javascript).

Getting started

Install

# npm
npm i --save oh-clif

# yarn
yarn add oh-clif

Usage

First let's build a command

MyCommand.ts

interface MyParams {
  message: string;
}

export default class MyCommand extends Command<MyParams> {
  // The key used to run your command
  get key(): string {
    return 'my-command';
  }

  get options(): Option[] {
    // Register all the options I can
    // pass to my command
    return [
      {
        name: 'message',
        attributes: {
          alias: 'm'
        }
      }
    ];
  }

  // What actually happens when i run
  // my command?
  async run(params: MyParams): Promise<void> {
    console.log(params?.message || 'No message');
  }
}

Now let's build a CLI

MyCLI.ts

class MyCLI extends CLI {
  get commands(): Command<any>[] {
    // Register my command
    return [new MyCommand()];
  }
}

Now we just need to call the init() function in our entrypoint

myScript.ts

#! /usr/bin/env node
new MyCLI().init();