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

@writ/command

v4.0.0

Published

Command parameter parsing for building cli applications

Downloads

3

Readme

@writ/command

Mime, Command parameter parsing for building cli applications. 中文

Table of Contents

Features

  • elegant command line parameter parsing
  • configure the build command line application

Install

install node.js, Now, install and use this project

   npm install @writ/command

Usage

  1. Project Structure

       ├─ example/      `usage examples`
       ├─ index.js      `entry points`
       ├─ test/         `test code`
       ├─ .gitignore    `git ignore`
       ├─ .eslintrc.js  `eslint format config`
       ├─ license       `agreement that`
       ├─ package.json  `table of modules with npm`
       └─ README.md     `description`
  2. Usage You can see my example here

    • Configuration using function types, You can do some work in the functions
       #! /usr/bin/env node
       const Command = require('@writ/command');
    
       new Command(function(command) {
          return require('../.clirc');
       }).start();
    • Configuration using object types
       #! /usr/bin/env node
       const Command = require('@writ/command');
    
       new Command({
          root: '.',
          order: {
             help: {
                   param: [],
                   alias: ['h', '-h']
             },
             version: {
                   alias: [
                      'v',
                      'V',
                      '-v',
                      '--version'
                   ]
             }
          },
          action: {
             help: require('../src/help'),
             version: require('../src/version')
          }
       }).start();
    • Configuration using string types
       #! /usr/bin/env node
    
       const Command = require('../../src');
       new Command('../example/.clirc.js').start();
  3. Options example

    • options.root[string] your cli-app root dir

    • options.action[string|object] command handler, it is a dirname or an object

    • options.order[object] command detail info

         // for example: 
         module.exports = {
            root: '.',
            action: {
               example(param) {
                     if (param.all) {
                        process.stdout.write(`All: ${param.all.join(' ')}\n`);
                     }
                     if (param.bail) {
                        process.stdout.write(`Bail: ${param.bail.join(' ')}\n`);
                     }
                     if (param.comment) {
                        process.stdout.write(`Comment: ${param.comment.join(' ')}\n`);
                     }
               }
            },
            order: {
               // Declare the 'example` subcommand
               example: {
                     // example's alias
                     alias: [
                        'ex',
                        '-e'
                     ],
                     // command parameters, the rule is the '--' beginning refers to the full name of the parameter, the '-' beginning refers to the corresponding abbreviation
                     // in a program, or will be converted to the full name, such as the '-a' convert 'param.all = []'
                     param: [
                        '--all -a',
                        '--bail -b',
                        '--comment -c'
                     ]
               }
            }
         }

      The above configuration implements a child command <main-command-name> example param, a command only alias and param two properties, and are currently only supports arrays, param statement for eachparamter in the code: --<name> -<alias>, all will be used in the corresponding action, referred to as "only to belong to convenient

  4. API intro In each action, this always points to your Command instances, So, you can use Command's methods and properties in each action.

    • root[string] your cli-app's root dir
    • actRoot[string] command handler file dir
    • action[object] commamd handlers
    • orders[object] command set
    • runtime[object] currently executing command's infomation
    • start(argv<[array]>) start loader
    • whoami(enter<[string]>) find currently command's name
    • parse(param<[array|*]>) parse currently command's options
    • invalid() print invaild infomation

Change log

  • Founded in Wed, 24 Oct 2018 01:38:45 GMT
  • Add the test case, Mon, 28 Jan 2019 05:01:27 GMT
  • Add usage, Sat, 16 Feb 2019 04:07:42 GMT

Resources