All Projects → sywac → Sywac

sywac / Sywac

Licence: mit
🚫 🐭 Asynchronous, single package CLI framework for Node

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Sywac

Neodoc
Beautiful, hand-crafted commandline interfaces for node.js
Stars: ✭ 221 (+102.75%)
Mutual labels:  command, parser, parsing
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (+15.6%)
Mutual labels:  cli, command, parser
Arg
Simple argument parsing
Stars: ✭ 897 (+722.94%)
Mutual labels:  cli, command, parser
Php Svg Lib
SVG file parsing / rendering library
Stars: ✭ 1,146 (+951.38%)
Mutual labels:  parser, parsing
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+836.7%)
Mutual labels:  cli, parser
Formula Parser
Parsing and evaluating mathematical formulas given as strings.
Stars: ✭ 62 (-43.12%)
Mutual labels:  parser, parsing
Executor
Watch for file changes and then execute command. Very nice for test driven development.
Stars: ✭ 14 (-87.16%)
Mutual labels:  cli, command
Lodestone Nodejs
Character tracking and parser library for nodejs
Stars: ✭ 81 (-25.69%)
Mutual labels:  parser, parsing
Parsing With Haskell Parser Combinators
🔍 A step-by-step guide to parsing using Haskell parser combinators.
Stars: ✭ 72 (-33.94%)
Mutual labels:  parser, parsing
Redrun
✨🐌 🐎✨ fastest npm scripts runner
Stars: ✭ 85 (-22.02%)
Mutual labels:  cli, parser
Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (-11.93%)
Mutual labels:  parser, parsing
Logos
Create ridiculously fast Lexers
Stars: ✭ 1,001 (+818.35%)
Mutual labels:  parser, parsing
Rocket
NetDisk in command line.
Stars: ✭ 40 (-63.3%)
Mutual labels:  cli, parser
Parser Javascript
Browser sniffing gone too far — A useragent parser library for JavaScript
Stars: ✭ 66 (-39.45%)
Mutual labels:  parser, parsing
Errorstacks
Tiny library to parse error stack traces
Stars: ✭ 29 (-73.39%)
Mutual labels:  parser, parsing
Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (-27.52%)
Mutual labels:  parser, parsing
Argumentum
C++ command line parsing library
Stars: ✭ 92 (-15.6%)
Mutual labels:  parser, argument-parser
Gql
Very simple CLI for many GraphQL schemas in the cloud. Provides autocompletion for GraphQL queries
Stars: ✭ 101 (-7.34%)
Mutual labels:  cli, command
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+1421.1%)
Mutual labels:  cli, argument-parser
Serve
Static file serving and directory listing
Stars: ✭ 7,444 (+6729.36%)
Mutual labels:  cli, command

sywac

So you want a CLI...

Build Status Coverage Status JavaScript Style Guide Dependabot Badge

A better CLI framework, made for the ES2015 era.

Visit https://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 recommend chalk)
  • Define styles/colors inline or decorate content with style hooks
  • Coherent API
  • Parse strings as easily as process.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 a cli.js file with code similar to this:

#!/usr/bin/env node

const cli = 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 = cli

async function main () {
  const argv = await cli.parseAndExit()
  console.log(JSON.stringify(argv, null, 2))
}

if (require.main === module) main()

Make the cli.js file executable:

$ chmod +x cli.js

And set up cli.js as the "bin" field in package.json:

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

Tip:

You can use npm 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.js
Usage: 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 --bool
Usage: 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 to http://sywac.io

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].