@learnersguild/game-cli
v2.1.4
Published
Option parser for Learners Guild commands.
Downloads
9
Maintainers
Readme
game-cli
Learners Guild game command-line interface (CLI).
Getting Started
Read the instructions for contributing.
Globally install nvm, avn, and avn-nvm.
curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash npm install -g avn avn-nvm avn setup
Clone the repository.
Run the setup tasks:
$ npm install $ npm test
How to Define New Commands
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
iftrue
, 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
iftrue
, the command or subcommand will be ignored
It's worth noting that the attributes are an extension of cliclopts.
How to Use
Install the module in your project
$ npm install --save @learnersguild/game-cli
Use whichever command modules you want by importing them
import {vote} from '@learnersguild/game-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
The Command Runner
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=<SUPER LONG TOKEN> vote 44 45
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:
{
"lgJWT" : "<LONG SSO JWT TOKEN>",
}
Notes
It may help to look at subcli for more detail on how the argument parsing is handled.
License
See the LICENSE file.