We want to align all command implementation to adhere to a pattern for ease code review, and maintenance; reduce defects; and generate documentations.
All command implementations are under src/commands
folder. Every command shall
have
-
.ts
file that implements the command.- has a function,
commandDecorator
which is the entry point to the command - this
commandDecorator
provide anaction
function for thecommander
library. action
command has to terminate by callingCommandBuilder.exit
function with a0
or1
status code forsuccesseful
orunsuccessful
execution respectively.
- has a function,
-
.test.ts
file that contains unit test for the command- code coverage shall be above 80%.
-
.json
file that contains the command declaration -
.md
file that contains detailed information about the command.- describe what this command is for (what it does)
- information that you think that users should be aware of
- sample(s) of the command
- Consistent verb and option naming conventions. For example, we standardize on
-o, --org-name
where-o
is the alias and--org-name
is the full option name for organization option. We do not use another aliases other than-o
and other name like--organization-name
. See Option Name Section - Consistent command syntax. We use commander open source library to enforce this.
- Common behaviors
- Consistent error messages. See Error Messages Section
- Command terminates with either 0 or 1 status code for successful or failed execution respectively.
- For interactive mode, we need to support an option to proivde a file that contains answers to all questions.
- All commands have to be well documented in its
.md
file - All commands have to be well tested (above 80% code coverage).
We want to have a consistent way for naming option and its alias for better user experience.
Use a noun or a well known abbreviation. E.g. do not use --pr
as an option
name for pull request. Use --pull-request
. --pr
can mean many different
things. And it is ok to use --url
because URL is a well known abbreviation.
Reuse the same option name in existing commands. E.g. use --org-name
because
it is already used in several commands; and do not create a new one like
--organization
or --organization-name
. To see all the existing option names
and aliases, type
ts-node tools/locateAliases.ts
Reuse the same alias in existing commands. E.g. use -o
for --org-name
because it is already used in several commands. To see all the existing option
names and aliases, type
ts-node tools/locateAliases.ts
In the event that you need to choose a new alias. Please follow these guidelines
- Do not use
-V
,-v
and-h
because they are reserved - Choose the first letter of the option name. For example, option name is
--key-value-name
, choose-k
- Choose the upper case of first letter of the option name if the above option
is not available. For example, option name is
--helm-chart
. We cannot use-h
because it is reserved. We can use-H
- Choose the last letter of the option name if the above option is not
available. For example, option name is
--helm-chart
. We cannot use-h
because it is reserved and-H
is already used by an option. we can use-t
- Choose the upper case of last letter of the option name if the above option
is not available. For example, option name is
--helm-chart
. we can use-T
- Choose the second letter of the option name if the above option is not
available. For example, option name is
--helm-chart
. we can use-e
. - Repeat the same process of as mentioned above until an alias is available.
Taking
--helm-chart
as example, the selected aliases are in this order
-h, -H, -t, -T, -e, -E, -r, -R, -l, -L, -a, -A, m, -M, -c, -C
- Every error messages shall have these format
<Error message in past tense>. <How to resolve it in present tense>.
E.g.
Value for organization name option was missing. Provide value for this option.
-
We do not want pronoun in error messages. E.g.
You did not enter value for organization name. Please provide value for it.
-
All error shall be created with the error builder, https://github.com/CatalystCode/spk/blob/master/src/lib/errorBuilder.ts so that we can generate the exception chain. In this manner, we can precisely know the root cause of the problem. For more information, refer to error handling.