Option parser for Learners Guild commands.
npm install @learnersguild/echo-cli


Learners Guild echo command-line interface (CLI).
Read the instructions for contributing.
1. Globally install [nvm][nvm], [avn][avn], and [avn-nvm][avn-nvm].
``bash`
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
npm install -g avn avn-nvm
avn setup
2. Clone the repository.
3. Run the setup tasks:
$ npm install
$ npm test
All of the existing top-level commands are defined in the config/commands folder, one .yaml file per command. To add a new command, simply create a .yaml file with the name of the command. Each command and subcommand supports the following attributes:
- name primary name of optionabbr
- one character alias of the optionalias
- other options treated as aliasboolean
- if true, the option is seen as a boolean flaghelp
- usage string for the optiondefault
- default value of the optioncommands
- nested subcommands, which also support this same list of attributes_inactive
- if true, the command or subcommand will be ignored
It's worth noting that the attributes are an extension of [cliclopts][cliclopts].
1. Install the module in your project
$ npm install --save @learnersguild/echo-cli
2. Use whichever command modules you want by importing them
`javascript
import {vote} from '@learnersguild/echo-cli'
const args = vote.parse(['44', '45'])
const usageText = vote.usage(args)
if (usageText) {
console.info(usageText)
return 1
}
// ... do something with args to make voting happen
`
There's a built-in command-runner that can be used for development / testing. It is implemented in /src/runner.js, and can be invoked as an npm script:
$ npm run command -- vote 44 45
The command runner supports different ways to authenticate / impersonate. The easiest way is to find the CLI_COMMAND_TOKEN environment variable, and send it along with the desired handle for the user as whom you'd like to authenticate. For example:
$ npm run command -- --token=abcd1234zyxw9876 --handle=joeschmoe vote 44 45
If you don't pass the handle option, the command runner will try to deduce it from your ~/.gitconfig by pulling the user attribute from the [github] section.
Alternatively, you can authenticate using a non-expired JWT that you can steal from your browser cookie using the browser developer tools. To do this, you can either pass that JWT along via the lgJWT option. For example:
$ npm run command -- --lgJWT=
If you don't pass the lgJWT option, the command runner will try to deduce it from a ~/.lgrc file that looks something like this:
`json``
{
"lgJWT" : "
}
It may help to look at [subcli][subcli] for more detail on how the argument parsing is handled.
See the LICENSE file.
[subcli]: https://github.com/LearnersGuild/subcli
[cliclopts]: https://github.com/finnp/cliclopts
[nvm]: https://github.com/creationix/nvm
[avn]: https://github.com/wbyoung/avn
[avn-nvm]: https://github.com/wbyoung/avn-nvm