Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

clefairy

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clefairy

Typed CLI argv parser and main function wrapper

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
937
9.85%
Maintainers
1
Weekly downloads
 
Created
Source

clefairy

CLI creation helper

  • Parses and validates argv according to your specification (and gives you TypeScript types)
  • Calls your function, and, if an error occurs (via sync throw or Promise rejection):
    • Pretty-prints the error
    • Exits the process with status code 1

Usage Example

import { run, optionalBoolean, requiredString, optionalString } from "clefairy";

run(
  {
    someColor: optionalString,
    someName: requiredString,
    v: optionalBoolean,
  },
  async (options, ...args) => {
    console.log({ options, args });
  },
  {
    // If you don't pass anything here, it defaults to process.argv.slice(2)
    // But I pass something here for this example to make it clearer how the
    // input argv maps to the options in the function.
    argv: ["-v", "--some-name", "Jeff", "one", "two", "--", "--hi"],
  }
);

// This gets logged:
// {
//   options: { v: true, someName: 'Jeff' },
//   args: [ 'one', 'two', '--hi' ]
// }

License

MIT

Keywords

cli

FAQs

Package last updated on 29 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts