Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🚫 🐭 Asynchronous, single package CLI framework for Node

License

NotificationsYou must be signed in to change notification settings

sywac/sywac

Repository files navigation

sywac

So you want a CLI...

Build StatusCoverage StatusJavaScript Style GuideDependabot Badge

A better CLI framework, made for the ES2015 era.

Visithttps://sywac.io for detailed documentation.NOTE! The docs site is still under construction.

Feature Highlights

  • Single package install
  • Asynchronous parsing, validation, and command execution
  • Type-based argument parsing
  • Plug in your own types or override/extend the built-in ones
  • Support for simple CLIs or complex nested command trees
  • First-class support for positional arguments, with or without commands
  • Flexible auto-generated help content
  • Support for ANSI styles/colors (we recommendchalk)
  • Define styles/colors inline or decorate content with style hooks
  • Coherent API
  • Parse strings as easily asprocess.argv
  • Supports concurrent parsing, safe for chatbots or other server-side apps

Quick Start Guide

First install sywac from npm:

$npm install --save sywac

Then create acli.js file with code similar to this:

#!/usr/bin/env nodeconstcli=require('sywac').positional('<string>',{paramsDesc:'A required string argument'}).boolean('-b, --bool',{desc:'A boolean option'}).number('-n, --num <number>',{desc:'A number option'}).help('-h, --help').version('-v, --version').showHelpByDefault().outputSettings({maxWidth:75})module.exports=cliasyncfunctionmain(){constargv=awaitcli.parseAndExit()console.log(JSON.stringify(argv,null,2))}if(require.main===module)main()

Make thecli.js file executable:

$chmod +x cli.js

And set upcli.js as the"bin" field inpackage.json:

{"name":"example","version":"0.1.0","bin":"cli.js"}

Tip:

You can usenpm init sywac to easily set up the above and add sywac to your project.

Then test it out. Without any arguments, it will print the help text.

$./cli.jsUsage: cli <string> [options]Arguments:  <string>  A required string argument                  [required] [string]Options:  -b, --bool          A boolean option                            [boolean]  -n, --num <number>  A number option                              [number]  -h, --help          Show help                  [commands: help] [boolean]  -v, --version       Show version number     [commands: version] [boolean]

Let's try passing some arguments:

$./cli.js hello -b -n 42{  "_": [],  "string": "hello",  "b": true,  "bool": true,  "n": 42,  "num": 42,  "h": false,  "help": false,  "v": false,  "version": false}

What happens if we pass flags without a string argument?

$./cli.js --boolUsage: cli <string> [options]Arguments:  <string>  A required string argument                  [required] [string]Options:  -b, --bool          A boolean option                            [boolean]  -n, --num <number>  A number option                              [number]  -h, --help          Show help                  [commands: help] [boolean]  -v, --version       Show version number     [commands: version] [boolean]Missing required argument: string

Validation failed and sywac printed the help text with an error message. Let's check the exit code of that last run:

$echo$?1

This is a good sign that our CLI will play well with others.

API

For details on the full API, go tohttp://sywac.io

License

MIT

About

🚫 🐭 Asynchronous, single package CLI framework for Node

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp