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

termos

v0.1.3

Published

Terminal framework for js

Downloads

9

Readme

Termos

Hot terminal framework for js

NPM

Termos is a package that lets you easily create CLI tools in Node.js using idiomatic ES6 syntax (Node 4+). It's also simple to create associated manual (help) pages for each command.

Usage

To use Termos, first install it in your Node project with npm install termos --save.

Next, modify your project's package.json to include:

"bin": {
  "mycli": "./cli.js"
}

Where mycli is the intended name of your command in the CLI.

Now create a file: ./cli.js and folder ./commands:

#!/usr/bin/env node

'use strict';

const CommandLineInterface = require('termos').CommandLineInterface;
const CLI = new CommandLineInterface();

CLI.load(__dirname, './commands');
CLI.run(process.argv.slice(2));

Finally, populate your commands directory with your commands, here's an example file: ./commands/example.js

module.exports = (() => {

  'use strict';

  const Command = require('termos').Command;

  class ExampleCommand extends Command {

    constructor() {

      super('example');

    }

    help() {

      return {
        description: 'An example command',
        args: ['example_arg1', 'example_arg2'],
        flags: {flag: 'An example flag'},
        vflags: {vflag: 'An example verbose flag'}
      };

    }

    run(args, flags, vflags, callback) {

      // Run code here.
      // To throw an error, use: callback(new Error(msg))
      // To optionally return a result, use: callback(null, result)

      callback(null);

    }

  }

  return ExampleCommand;

})();

Creating manual pages (help)

View all the commands available to your CLI with mycli help where mycli is the intended name of your command in the CLI. To modify help information, change the return value of the help() method for each command.

Creating Subcommands

To subclass a command (i.e. mycli command_name:sub_name) simply change the contructor() method in your command to the following:

constructor() {

  super('command_name', 'sub_name');

}

Running your commands

Each command has a run() method which takes three arguments: args, flags, and vflags.

args

args is the array of arguments, passed before any flags.

i.e. mycli command alpha beta would populate args with ['alpha', 'beta']

flags

flags is an object containing any flags (prefixed with -), where each entry is an array of values passed after the flag

i.e. mycli command -f my flag would populate vflags with {f: ['my', 'flag']}

vflags

vflags works identically to flags, but with "verbose flags" (prefixed with --).

Additional notes

All argument arrays passed to args or any flags or vflags options will be separated by spaces, except in the case of quotation marks. Use quotation marks to specify an argument with spaces in it.

i.e. mycli command -f "argument one" argument_two

Acknowledgements

Thanks for checking out the library! Feel free to submit issues or PRs if you'd like to see more features.

Based on cmnd.