CLI utility that parses argv, loads your specified file, and passes the parsed argv into your file's exported function. Supports ESM/TypeScript/etc out of the box.

Overview

cleffa

CLI tool that:

  • Parses argv into an object (of command-line flags) and an array of positional arguments
  • Loads a function from the specified file (supports JavaScript, TypeScript, ESM, etc)
  • Calls your function with that object and any positional args, and, if an error occurs (via sync throw or Promise rejection):
    • Pretty-prints the error
    • Exits the process with status code 1

It's an untyped CLI version of clefairy, suitable for use in simple scripts/programs.

Usage Example

some-file.js:

export default async function main(options, ...args) {
  console.log({ options, args });
}

Then, if you run:

npx cleffa ./some-file.js --user-name Jeff one two -v -- --hi

It logs:

{
  options: { userName: 'Jeff', v: true },
  args: [ 'one', 'two', '--hi' ]
}

Supported Syntax

Your input file will be compiled with kame prior to execution. As such, you can use ESM and TypeScript syntax in your input file.

Shebang Usage (use without installing)

You can put this line at the top of any executable JavaScript/TypeScript file to make it run with cleffa anywhere that node is installed:

#!/usr/bin/env -S npx --yes cleffa

For example, if you made a file named print-files (this is a contrived example):

#!/usr/bin/env -S npx --yes cleffa
import fs from "fs";

export default function main(options, ...args) {
  for (const file of args) {
    console.log(fs.readFileSync(file, "utf-8"));
  }
}

Then marked it as executable:

$ chmod +x ./print-files

Then ran it:

$ ./print-files ./index.js ./index.ts

It would print the contents of index.js and index.ts.

License

MIT

You might also like...

Automaticly parses known pocket ips patch resources, scans folders or zip files for matching roms and applies the patches.

Pocket Automaton Automaticly parses known pocket ips patch resources, scans folders or zip files for matching roms and applies the patches. Usage pock

Nov 27, 2022

utility library for promise, support both commonjs and ESM

promising-utils A utility library for promise, supports both commonjs and ESM npm install promising-utils --save yarn add promising-utils wait Used wh

Oct 18, 2022

Custom alert box using javaScript and css. This plugin will provide the functionality to customize the default JavaScript alert box.

customAlertBoxPlugin Custom Alert Box Plugin Using JavaScript and CSS Author: Suraj Aswal Must Include CSS Code/Default Custom Alert Box Class: /* mus

Sep 10, 2022

Minimal utility to convert to or from any timezone. Deno/Node/Browser. ESM/CommonJS.

minitz Features Convert dates between any timezone supported by the system. Parses ISO8601 time strings. MIT licensed, use the library any way you wan

Oct 10, 2022

Typescript package compatible with python's pickle loads/dumps

picklefriend Typescript package compatible with python's pickle loads/dumps Installation npm i picklefriend Usage import { pickle } from 'picklefriend

Oct 27, 2022

Zemi is data-driven and reverse-routing library for Express. It provides out-of-the-box OpenAPI support, allowing you to specify and autogenerate an OpenAPI spec.

zemi zemi is a data-driven routing library for Express, built with Typescript. Features: optional, out-of-the-box support for OpenAPI reverse-routing

Jul 23, 2022

Scaffold a full-stack SvelteKit application with tRPC and WindiCSS out of the box

create-sweet-app Interactive CLI to quickly set up an opinionated, full-stack, typesafe SvelteKit project. Inspired by the T3 Stack and create-t3-app

Dec 16, 2022

Cross provider map drawing library, supporting Mapbox, Google Maps and Leaflet out the box

Terra Draw Frictionless map drawing across mapping providers. TerraDraw centralises map drawing logic and provides a host of out the box drawing modes

Dec 31, 2022

FortuneSheet is an online spreedsheet component library that provides out-of-the-box features just like Excel

FortuneSheet FortuneSheet is an online spreedsheet component library that provides out-of-the-box features just like Excel English | 简体中文 Purpose The

Jan 3, 2023
Owner
Lily Scott
Former Prettier Core Team member, Former Babel team member. Interested in JavaScript, Rust, Unity, VR, Dev Tooling, Dev Experience, React, and more.
Lily Scott
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022
Babel plugin and helper functions for interoperation between Node.js native ESM and Babel ESM

babel-plugin-node-cjs-interop and node-cjs-interop: fix the default import interoperability issue in Node.js The problem to solve Consider the followi

Masaki Hara 15 Nov 6, 2022
A typescript transform that converts exported const enums into object literal.

ts-transformer-optimize-const-enum A typescript transformer that convert exported const enum into object literal. This is just like the one from @babe

Fonger 22 Jul 27, 2022
CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files.

convert-to-oklch CLI tool that converts rgb(), rgba(), hex, hsl() and hsla() colors to oklch() in specified CSS files. npx convert-to-oklch ./src/**/*

Fedya Petrakov 43 Dec 20, 2022
A small CLI to sort any specified json files alphabetically

This is a small CLI to sort any specified json files alphabetically. This was created to sort localization files, but maybe you will find another use case.

PLAYT.net 4 Mar 20, 2022
Some out-of-the-box utility features based on the Oasis engine.

Engine Toolkit Some out-of-the-box utility features based on the Oasis engine Script, welcome to enjoy! Features ?? Controls - Some camera controllers

Oasis 22 Nov 21, 2022
SAP Community Code Challenge: This repository contains an empty OpenUI5 application and end-to-end tests written with wdi5. Take part in the challenge and develop an app that passes the tests.

SAP Community Code Challenge - UI5 The change log describes notable changes in this package. Description This repository is the starting point for the

SAP Samples 8 Oct 24, 2022
microregex is an open source and highly curated catalog of regular expression patterns. It offers programmers RegEx snippets that can be quickly exported into a variety of programming languages and distributed around teams.

microregex - A catalog of RegEx patterns View Demo · Report Bug · Request Feature Loved the tool? Please consider contributing ✍️ to help it improve!

Sunit Shirke 4 Oct 25, 2022
Out-of-the-box MPA plugin for Vite, with html template engine and virtual files support.

vite-plugin-virtual-mpa Out-of-the-box MPA plugin for Vite, with html template engine and virtual files support, generate multiple files using only on

QinXuYang 21 Dec 16, 2022
ln-charts parses the output of bos accounting commands into various charts for your Lightning Node.

ln-charts ln-charts parses the output of bos accounting commands into various charts for your Lightning Node. It runs on Angular, JS, HTML, CSS, ngx-c

Steven Ellis 21 Dec 18, 2022