npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bob-core

v1.0.1

Published

BOB Core

Downloads

149

Readme

BOB Core - Bash Operation Buddy Core

Introduction

BOB (Bash Operation Buddy) Core is a library that provides a set of functions to create your own CLI in TypeScript easily.

Usage

npm install bob-core

Initialize the CLI:

import { CLI } from 'bob-core';

const cli = new CLI();

await cli.withCommands('./commands');

cli.run('commandName', 'arg1', 'arg2', 'arg3');

Create a command in the commands folder:

import { Command } from 'bob-core';

export default class MyCommand extends Command {
  public name = 'my-command {arg1} {--option1}';
  public description = 'This is my command';
  
  /**
   * Define the arguments and options help
   *
   * Optional
   */
  helpDefinition = {
      arg1: 'This is the first argument',
      '--option1': 'This is the first option'
  }

  /**
   * Provide examples of how to use the command
   *
   * Optional
   */
  commandsExamples = [
      {
            command: 'my-command value1 --option1',
            description: 'This is an example'
      }
  ]

  public async handle() {
    console.log('Hello World');
    console.log('Arguments:', this.argument('arg1'));
    console.log('Options:', this.option('option1'));
  }
}

Cli Help

The CLI provides a help command that displays all available commands and their descriptions.

node cli.js help

Commands

Bob CLI x.x.x 💪

Usage:
  command [options] [arguments]

Available commands:

help         Show help
test         test description
sub:
  sub        sub command description
  sub:sub    sub:sub command description

Command help

You can also display the help of a specific command.

node cli.js test -h
Description:
  test description

Usage:
  test <user> [options]

Arguments:
  user                  user description
  test                  test description [default: null]
  test2                 [default: []] (variadic)

Options:
  --option, -o, -b      option description (boolean) [default: false]
  --flag                flag description (string) [default: null]
  --arr                 arr description (array) [default: null]
  --flag2               flag2 description (string) [default: 2]
  --help, -h            Display help for the given command. When no command is given display help for the list command (boolean)

Examples:
  Example description 1

    node cli.js test yayo --option

  Example description 2

    node cli.js test anothervalue --flag=2

Depending on the command, the help will display the command signature, description, arguments, options and examples.

Commands signature

The command signature is a string that defines the command name, arguments and options.

Example:

    signature = 'my-command {arg1} {arg2} {arg3} {--option1} {--option2}';

Arguments

All user supplied arguments and options are wrapped in curly braces. In the following example, the command defines three required arguments arg1, arg2 and arg3.

    signature = 'my-command {arg1} {arg2} {arg3}';

You may want to make an argument optional by adding a ? after the argument name or by providing a default value with =.

    signature = 'my-command {arg1} {arg2?} {arg3=defaultValue}';

    handle() {
        this.argument('arg1'); // 'value' or throw an error if not provided
        this.argument('arg2'); // 'value' or null if not provided
        this.argument('arg3'); // 'value' or 'defaultValue' if not provided
    }

You can also define a variadic argument by adding * after the argument name. Variadic arguments are stored in an array.

    signature = 'my-command {arg1} {arg2*}';

    handle() {
        this.argument('arg1'); // 'value1'
        this.argument('arg2'); // ['value2', 'value3']
    }

Variadic arguments can also be optional.

    signature = 'my-command {arg1} {arg2*?}';

Options

Options are defined by {--optionName}.

    signature = 'my-command {--option1} {--option2} {--option3}';

By default options are boolean with a default value of false. You can also change the option type to string by adding = to the option definition. You can also provide a default value by adding =value.

If the value is 'true' or 'false', the option will be converted to a boolean.

    signature = 'my-command {--option1} {--option2=true} {--option3=} {--option4=defaultValue} {--option5=}';

    handle() {
        this.option('option1'); // by default `false` and can be set to `true` by the user 
        this.option('option2'); // by default `true` and can be set to `false` by the user
        this.option('option3'); // by default `null` and can be set to "value" by the user
        this.option('option4'); // by default "defaultValue" and can be set to "value" by the user
    }

You can also define a variadic option by adding * as option value. (e.g. {--option2=*}) Variadic options are stored in an array.

    signature = 'my-command {--option1} {--option2=*}';

    handle() {
        this.option('option1'); // 'value1' 
        this.option('option2'); // ['value2', 'value3'] // or [] if not provided
    }

Commands I/O

Arguments

    this.argument('arg1');

You can also provide a default value if the argument is optional.

    this.argument('arg1', 'defaultValue');

If you always need a boolean value, you can use the argumentBoolean method.

    this.argumentBoolean('arg1');

If you always need a number value, you can use the argumentNumber method.

    this.argumentNumber('arg1');

If you always need a array value, you can use the argumentArray method.

    this.argumentArray('arg1');

Options

    this.option('option1');

You can also provide a default value if the option is optional.

    this.option('option1', 'defaultValue');

If you always need a boolean value, you can use the optionBoolean method.

    this.optionBoolean('option1');

If you always need a number value, you can use the optionNumber method.

    this.optionNumber('option1');

If you always need a array value, you can use the optionArray method.

    this.optionArray('option1');