Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Commander for Actionhero CLI #1670

Merged
merged 3 commits into from
Dec 8, 2020
Merged

Use Commander for Actionhero CLI #1670

merged 3 commits into from
Dec 8, 2020

Conversation

evantahler
Copy link
Member

@evantahler evantahler commented Dec 8, 2020

This PR greatly simplifies the running and generation of Actionhero CLI commands.

➜  actionhero ./node_modules/.bin/actionhero help
Usage: actionhero [options] [command]

Options:
  -V, --version                   output the version number
  -h, --help                      display help for command

Commands:
  actions                         List the actions defined on this server
  console                         Start an interactive REPL session with the api object in-scope
  generate                        Generate a new Actionhero Project in an empty directory
  generate-action [options]       Generate a new Action
  generate-cli [options]          Generate a new cli command
  generate-initializer [options]  Generate a new Initializer
  generate-plugin                 Generate the structure of a new actionhero plugin in an empty directory
  generate-server [options]       Generate a new Server
  generate-task [options]         Generate a new Task
  task-enqueue [options]          Enqueue a defined Task into your actionhero cluster
  help [command]                  display help for command
➜  actionhero ./node_modules/.bin/actionhero generate-action -h
Usage: actionhero generate-action [options]

Generate a new Action

Options:
  --name <name>
  --description <description>   (default: "an actionhero action")
  -h, --help                   display help for command

Example:
  actionhero generate action --name=[name] --description=[description]
  • We now use commander to be the main "runner" for our CLI commands
    • it handles build help and parsing of inputs automatically!
    • it works on windows!
  • Even when opting out of the commands which come with Actionhero core, you'll still have access to auto-generated help and version commands
  • The format of the CLI commands themselves remain largely unchanged! We still source your inputs (required, defaults, etc), name, and example.
  • The CLI logic is now exportable to by used by custom CLI runners (ie: you want to make your own command to run, not using actionhero)

Downsides:

  • You'll need to compile (npm run build) your commands before using them. You can use the tsc --watch workflow to speed things up

BREAKING CHANGES:

  • Commands now have optional initialize and start options, so you can opt-into initializing or starting your server as needed for your CLI command. The default is to initialize initialize=true but not start (start=false)
  • Command names with spaces now have -. IE: actionhero generate action is now actionhero generate-action, etc.

@evantahler evantahler added enhancement New feature or request BREAKING-CHANGE labels Dec 8, 2020
@evantahler evantahler requested a review from gcoonrod December 8, 2020 04:57
const { stdout } = await doCommand(`${binary} version`);
expect(stdout).toContain(pacakgeJSON.version);
const { stdout } = await doCommand(`${binary} --version`);
expect(stdout).toContain("0.1.0"); // this project's version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to have to be updated regularly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, but this is test is in the context of a newly generated project (we make a whole new project in /tmp). The package.json which gets generated for new projects is always v0.1.0 https://github.com/actionhero/actionhero/blob/master/templates/package.json.template#L5

@evantahler evantahler marked this pull request as ready for review December 8, 2020 16:13
@evantahler evantahler merged commit 0376849 into master Dec 8, 2020
@evantahler evantahler deleted the cli branch December 8, 2020 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING-CHANGE enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants