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

lineparser

v0.9.8

Published

A meta-data driven command line parser for Node.js

Downloads

10

Readme

line-parser-js

A meta driven command line parser for Node.js

#!/usr/bin/env node

var meta = {
    program : 'adb',
    name : 'Android Debug Bridge',
    version : '1.0.3',
    subcommands : [ 'connect', 'disconnect', 'shell', 'push', 'install' ], 
    options : {
        flags : [
            [ 'h', 'help', 'print program usage' ],
            [ 'r', 'reinstall', 'reinstall package' ],
            [ 'l', 'localhost', 'localhost' ]
        ],
        parameters : [
            [ null, 'host', 'adb server hostname or IP address', null ],
            [ 'p', 'port', 'adb server port', 5037 ]
        ]
    },
    usages : [
        [ 'connect', ['host', '[port]'], null, 'connect to adb server', adb_connect ],
        [ 'connect', [ 'l' ], null, 'connect to the local adb server', adb_connect ],
        [ 'disconnect', null, null, 'disconnect from adb server', adb_disconnect ],
        [ 'shell', null, ['[cmd]'], 'run shell commands', adb_shell ],
        [ 'push', null, ['src', 'dest'], 'push file to adb server', adb_push ],
        [ 'install', ['r'], ['package'], 'install package', adb_install ],
        [ null, ['h'], null, 'help', adb_help ],
        [ null, null, null, 'help', adb_help ]
    ]
};

try {
    var lineparser = require('lineparser');
    var parser = lineparser.init(meta);

    // print help
    var help = parser.help();
    console.log(help);

    // the handler adb_connect will be invoked
    parser.parse(['connect', '--host', '10.69.2.186', '--port', '5036']);
    
    // the handler adb_install will be invoked
    parser.parse(['install', '-r', '/pkgs/bird.apk']);

    // the handler adb_push will be invoked
    parser.parse(['push', '/pkgs/bird.apk', '/data/tmp']);

    // the handler adb_shell will be invoked
    parser.parse(['shell', 'ls', '-l', '/data/data/']);
}
catch (e) {
    // exception will be thrown if there're errror with the meta data
    console.error(e);
}


// usage handlers
function adb_help(r) {
    console.log(r.help());
}

function adb_connect(r) {
    if (r.flags.l) {
        console.log('Connect to localhost:5037'); 
    }
    else {
        console.log('Connect to ' + r.parameters.host + ':' + r.parameters.p); 
    }
}

function adb_disconnect(r) {
    console.log('Disconnect'); 
}

function adb_shell(r) {
    if (0 == r.args) {
        console.log('Enter adb shell');
    }
    else {
        var cmd = 'Run command: '
        for (var i = 0; i < r.args.length; ++i) {
            cmd += ' ' + r.args[i]; 
        }
        console.log(cmd);
    }
}

function adb_push(r) {
    console.log('Push file ' + r.args[0] + ' to ' + r.args[1]); 
}

function adb_install(r) {
    console.log('Install package ' + r.args[0] + ', reinstall: ' + r.flags.r); 
}