You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+243Lines changed: 243 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,249 @@ We try to follow the coding guidelines from the Go community.
127
127
- Code should be commented
128
128
- Code should pass all tests: `make test`
129
129
130
+
# CLI Guidelines
131
+
This is a design guideline used for the development of the Flow CLI. The purpose of this guideline is to achieve consistency across new features and allow composability of commands that build the fundamentals of great CLI design.
132
+
133
+
> Whatever software you’re building, you can be absolutely certain that people will
134
+
> use it in ways you didn’t anticipate. Your software will become a part in a larger system
135
+
> — your only choice is over whether it will be a well-behaved part. - [Clig](https://clig.dev/)
136
+
137
+
138
+
# Human Interaction
139
+
140
+
Our interaction with the CLI is done by executing CLI commands and passing arguments
141
+
and flags which need to be consistent. Consistency will allow interactions to
142
+
be predictable and will with time feel natural even without resorting to reading instructions.
143
+
144
+
## Commands
145
+
Be consistent across commands and subcommands. In case we define a subcommand we
146
+
should use `noun verb` pattern. **Don’t have ambiguous or similarly-named commands.**
147
+
Naming and language should be the same as used in the rest of Flow's documentation.
148
+
Use only lowercase letters, and dashes if you really need to. Keep it short.
149
+
Users will be typing it all the time.
150
+
151
+
```
152
+
flow accounts
153
+
```
154
+
155
+
## Flags
156
+
Flags are **named parameters**, denoted with either a hyphen, and a
157
+
single-letter name (`-r`) or a double hyphen and a multiple-letter
158
+
name (`--recursive`). The longer version is preferred for better readability
159
+
and simpler learning experience in the beginning but after a while users will
160
+
probably start using the shorter version.
161
+
162
+
Every flag should have a shorter version and they should be both presented in the help.
163
+
Every flag that can have a default value should have a default value
164
+
so users don’t have to specify all of them when not needed.
165
+
166
+
Support flags following a value delimited by a space or
167
+
equal (=) sign (ex: `--username test` or `--username=test`)
168
+
169
+
```
170
+
flow accounts get --filter "address"
171
+
```
172
+
173
+
Use common naming for default falgs such as:
174
+
175
+
`--log`: Logging level.
176
+
177
+
`--output`: Output format (JSON, inline etc...).
178
+
179
+
`-h, --help`: Help. This should only mean help. See the help section.
180
+
181
+
`--version`: Version.
182
+
183
+
184
+
## Arguments
185
+
Arguments, or args, are positional parameters to a command.
186
+
There should be as few arguments as possible, because it is hard for users to remember the sequence of arguments.
187
+
188
+
Because they are relying on position, flags should be used where more than one argument would be required.
189
+
190
+
Arguments should be one word verbs following general naming guideline.
191
+
**Prefer flags to arguments**.
192
+
193
+
Use an argument for the value that command requires in order to run.
194
+
195
+
```
196
+
flow accounts get <address>
197
+
```
198
+
199
+
## Robustness
200
+
CLI should feel robust. Long operation should also provide output as they are processing.
201
+
**Responsivness is more important than speed.**
202
+
203
+
Warn before you make a non-additive change. Eventually, you’ll find that you can’t
204
+
avoid breaking an interface. Before you do, forewarn your users in the program itself:
205
+
when they pass the flag you’re looking to deprecate, tell them it’s going to change soon.
206
+
Make sure there’s a way they can modify their usage today to make it
207
+
future-proof, and tell them how to do it.
208
+
209
+
# Computer Interaction
210
+
211
+
The CLI will respond to execution of commands by providing some output.
212
+
Output should with the same reasons as input be consistent and predictable,
213
+
even further it should follow some industry standards and thus allow great strength
214
+
of CLI use: composability. Output should be served in the right dosage. We shouldn't
215
+
output lines and lines of data because we will shadow the important part the same
216
+
way we shouldn't let the CLI command run in background not providing any output for
217
+
minutes as it is working because the user will start to doubt if the command is broken.
218
+
It's important to get this balance right.
219
+
220
+
## Interaction
221
+
Commands must be stateless and idempotent, meaning they can be run without relying on external state.
222
+
If we have some external state, like the configuration, each command must include an option to
223
+
define it on the fly, but it must also work without it by first relying on the externally
224
+
saved state in the configuration, and if not found, relying on a default value.
225
+
When relying on a default value results in an error, there should be an explanation for the user that a configuration should be created.
226
+
227
+
We try to use default values first to get that “works like magic” feeling.
228
+
229
+
Never require a prompt for user input. Always offer a flag to provide that input.
230
+
However, if a user doesn't provide required input we can offer a prompt as an alternative.
231
+
232
+
233
+
## Output
234
+
235
+
“Expect the output of every program to become the input to another, as yet unknown, program.” — Doug McIlroy
236
+
237
+
Output should use **stdout**. Output of commands should be presented in a clear formatted way for
238
+
users to easily scan it, but it must also be compatible with `grep` command often used in
239
+
command chaining. Output should also be possible in json by using `--output json` flag.
240
+
241
+
Default command response should be to the stdout and not saved to a file. Anytime we want
242
+
the output to be saved to a file we should explicitly specify so by using `--save filename.txt`
243
+
flag and providing the path.
244
+
245
+
246
+
```
247
+
Address 179b6b1cb6755e31
248
+
Balance 0
249
+
Keys 2
250
+
251
+
Key 0 Public Key c8a2a318b9099cc6c872a0ec3dcd9f59d17837e4ffd6cd8a1f913ddfa769559605e1ad6ad603ebb511f5a6c8125f863abc2e9c600216edaa07104a0fe320dba7
0 commit comments