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

strict-args

v0.3.0

Published

A NodeJS arguments library which strictly enforces flag presence, command syntax, alerts on unexpected flags, and manages help and command outputs.

Downloads

1

Readme

NodeJS Strict Args

npm version Build and Test

GitHub Wiki
GitHub Issue Tracker

A NodeJS arguments library which strictly enforces flag presence, command syntax, alerts on unexpected flags, and manages help and command outputs. This library's goal is to make developing new command line tools in Node easy and user-friendly.

See this project's GitHub Wiki for API documentation.

This library is a spiritual successor to @ava-cassiopeia/really-simple-args, with a focus on stricter syntax checking.


Quickstart

To start, import strict-args as a (non-dev) dependency:

npm install --save strict-args

Then declare the available commands and flags for your tool:

import {StrictArgs, FlagType} from "strict-args";

const strictArgs = new StrictArgs(
    // The name of your tool. This should match how the tool is invoked in the
    // command line, ie. if one types "fakecli" then the name here should be
    // "fakecli".
    /* name= */ "fakecli",
    // The description of your tool. This is printed on the various help screens
    // that StrictArgs will render if needed.
    /* description= */ "A fake CLI that does something interesting.");

// Declare commands, including optional flags for those commands.
strictArgs.registerCommand({
  name: "start",
  description: "Starts the webserver on port 8080.",
  flags: [
    {
      name: "debug",
      description: "If present, enables debug mode.",
      type: FlagType.FLAG, // flags don't take values
    },
    {
      name: "port",
      description: "Optional port for the server to run on. Defaults to 8080.",
      default: "8080",
      type: FlagType.PROPERTY, // properties take values
    },
  ],
});
strictArgs.registerCommand({
  name: "stop",
  description: "Stops any running webserver.",
});

// Optionally register global flags, ie. flags that are available for any
// command.
strictArgs.registerGlobalFlag({
  name: "some-flag",
  description: "Does something interesting when present.",
});

// Register "command listeners". Command listeners are classes which implement
// a common interface, and have a class method which is called whenever the
// specified command is run.
// See the section on command listeners for more information.
strictArgs.addCommandListener("start", (a) => new StartCommandListener(a));

// Once all setup and registration is complete, run parse() to run the program.
// Command listeners will automatically be called if the user specifies a
// command and flags correctly, otherwise the program will exit with a message
// explaining to the user how to use the application / what they did wrong.
strictArgs.parse(process.argv);

Contributing

GitHub Issue Tracker

Feel free to file bugs and feature requests in the GitHub issue tracker.

Pull requests are also very much welcome, and will be reviewed on a "best effort" basis. This is typically within a few days, but can sometimes take awhile as this project is maintained by one human.

More information is available for developing with the codebase below.

Development

NodeJS and NPM are required to do development on this project. You can find installers or installation instructions for both here: nodejs.org. Once those are installed, see below.

When your change feels complete, please send a PR where possible so I can merge your code with the main code and publish it under the relevant NPM package.

To build the TypeScript code, run:

npm run build

To test the TypeScript code, run:

npm test

To test a local, fake CLI (code in manualtest/):

npm run manualtest