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

go-plugin-cli

v2.0.0

Published

Go plugin to create and execute commmands

Downloads

451

Readme

go-plugin-cli

npm Travis Coveralls Vulnerabilities js-standard-style

Go plugin to create and execute commmands.

This plugin is made on top of Liftoff. Thanks @jonschlinkert, @phated, tkellen and tusbar for it!

Table of Contents

Usage

Installation

$ npm install --save-dev go go-plugin-cli
import go from 'go'
import { CliPlugin } from 'go-plugin-cli'
go.use(CliPlugin)

Quick Start

Cli Plugin helps you to create command-line interface for your boilerplate and commands. You can easily create interactive menus for your app when using it in pair with Go CLI. For example, you may want to provide install command in CLI:

// gofile.js in root directory of your application
import go from 'go'
import { CliPlugin } from 'go-plugin-cli'
go.use(CliPlugin)

go.registerCommand('greet', async () => {
  console.log('Welcome!')
})
$ go greet
Welcome!

Api

Methods

registerCommand

go.registerCommand( commands [ , callback ] ): void
  • commands {string|object|array} — can be a string that will result in a name of a command, an object with command options or an array of mixed string and objects
  • callback {function} — becomes a callback for a command when commands is a string

Registers new command to the list.

matchCommand

go.matchCommand( commandString ): Command
  • commandString {string} — a string with the name of command and flags

Find a registered command.

executeCommand

go.executeCommand( commandString ): Promise<any>
  • commandString {string} — a string with the name of command and flags

Find and execute registered command.

getCommands

go.getCommands(): Command[]

Returns a RAW list of registered commands.

CLI

$ go # to run interactive menu
$ go command with flags # to run the registered command

Command

Command is an object with options. Here is the list of possible options:

name

  • Required
  • Valid types: string

The name of the command that will be used to trigger it.

callback

The callback function will be called when command is triggered.

commands

Nested commands can be triggered by using their name after the name of parent command, or from interactive menu.

description

  • Valid types: string

The description of the command that will be shown in the interactive menu.

title

  • Valid types: string
  • Default value: "Choose command:"

The title will be shown in interactive menu for nested commands.

prefix

  • Valid types: string
  • Default value: "GO"

The prefix will be shown in interactive menu for nested commands.

when

  • Valid types: string|array|object|function
  • Function arguments: object (parsed command)

Adds additional check when matching command. This lets you use the same command name and trigger different commands depending on flags or environment.

If when is specified as a string it will match the command only if specified flag has truthy value. when can also be specified as an array of string's. Then the precense of each mentioned flag will be validated. To check the specific value of the flag when can be given as an object in a format { flagName: flagValue }.

For more control function can be used as when option. It should return either truthy or falsy value and that will determine if command is matching or not.

options

  • Valid types: object

The configuration object for parsing command. When used in nested command it iherits options from parent commands. Read parsing command options section to learn more about it.

Parsed Command

Command callbacks receive parsed CLI command as an argument. The structure of an object:

  • args {object} — parsed command
    • _ {array} — the list of command partials (strings)
    • [flag name] {boolean|string} — values of each given flag
    • -- {array} — the list of strings given after -- sign

Parsing Command Options

There is an option to configure how command will be parsed. This is an object that can be written in 2 ways: { flagName: type } or { flagName: options }

List of options:

  • type {Boolean|String} — defines how flag should be parsed
  • alias {string|array} — alias string or an array of alias strings
  • default {any} — default value when flag is not used

Examples

License

MIT © Stanislav Termosa