Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): move version logging earlier in CLI to allow
-v
, --version
This moves the version logging earlier in the `run` function for our CLI so that it's possible to log the version by doing any of - `stencil version` - `stencil -v` - `stencil --version` Prior to this change only `stencil version` would work, although we had code which was clearly intended to log the version in the case that `-v` or `--version` is passed. Background: Stencil's CLI distinguishes between _tasks_ and _flags_. A _task_ is the first CLI argument and does not start with a leading dash. It's basically treated as a subcommand, so in a CLI invocation of Stencil like `stencil build` the _task_ for Stencil will be `build`. We already support `version` as a valid task. A _flag_, by contrast, is a CLI option which controls an aspect of how Stencil runs. It's passed at the command-line like `--foo`, `--foo=bar`, or something along those lines. When there's no task passed to the stencil CLI we normally log the help text, in-line with conventional CLI UX. This means that if you do something like `stencil --build` by accident you'll get help text explaining how to invoke Stencil correctly. All well and good. However, although we've long supported `stencil version` we also have code in `main` which clearly intends to special-case the `version` _flag_ and treat it as if it is a _task_, so that if you do `stencil -v` or `stencil --version` it will be treated as if you'd done `stencil version`. The code is here: https://github.com/ionic-team/stencil/blob/1eec9a82a4d623d46228e84798adbf2f88d7f3e8/src/cli/run.ts#L56-L59 The reason that this wasn't running as intended is that earlier in the same function we would log the help text if a _task_ wasn't provided: https://github.com/ionic-team/stencil/blob/1eec9a82a4d623d46228e84798adbf2f88d7f3e8/src/cli/run.ts#L40-L44 Note the `if (!task` there. So because of this is you did `stencil -v` we would log the help text and execution wouldn't reach the lower version-related block. To fix this we just move the version logging code above the help text logging code. STENCIL-997
- Loading branch information