alwaysai / alwayscli

A framework for building command-line interfaces in Node.js
Other
6 stars 2 forks source link

Overhaul of the externally-facing API #20

Closed carnesen closed 5 years ago

carnesen commented 5 years ago

This PR is a fairly significant non-backwards-compatible overhaul to the externally-facing API of this package. See https://github.com/alwaysai/cli/pull/95 see see the ramifications of this change on the alwaysai CLI. This PR also increases unit test coverage of this library to ~98%.

Top-level API naming convention: Use PascalCase for factories instead of camelCased-"create" words, e.g. createJsonInput --> CliJsonInput. Consistently include the identifier "Cli" for better grep-ability, e.g. UsageError => CliUsageError. These changes are all pretty straightforward to incorporate into a consumer such as the alwaysai CLI via global search and replace.

Change property names of the CliInput type: args --> positionalInput, options --> namedInputs, and escaped --> escapedInput. These new names are more descriptive and grep-able.

Replace createCli + runAndExit by:

Both CliArgvInterface and runCliAndExit take an optional enhancer argument inspired by the enhancer feature of Redux. The enhancer signature is (argvInterface) => argvInterface. Enhancers allow you to wrap the argvInterface to do stuff before or after it runs. See the alwaysai CLI enhancer for an example that logs/tracks command invocations and exceptions.

As a new feature I rolled into this change, in runCliAndExit, if the argvInterface throws an error with a numeric "code" property, it process.exits with that code.

carnesen commented 5 years ago

Verbally approved by @ryanmalone