Skip to content

Commit f75ebff

Browse files
committed
Update docs to show latest option naming feature
1 parent 268ded5 commit f75ebff

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

docs/tutorial/intro.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -230,38 +230,38 @@ of their Python name. Options do not have a short name by default.
230230
Option names can be controlled by prefixing their description with a value in square brackets `[]`:
231231

232232
* `[-t]` → `-t` is the short name
233+
* `[--to]` → `--to` is the long name
233234
* `[-t/--to]` → `-t` is the short name and `--to` is the long name
235+
* `[-t/]` → `-t` is the short name, the long name is *removed*.
234236

235237
<div align="right" class="code-source"><sub>
236238
<a href="https://github.com/treykeown/arguably/blob/main/etc/scripts/hello-6.py">[source]</a>
237239
</sub></div>
238240

239241
```python
240242
@arguably.command
241-
def hello(*from_, name="world"):
243+
def hello(*, from_="me", name="world"):
242244
"""
243245
this will say hello to someone
244246
245247
Args:
246-
from_: greetings are sent from these people
247-
name: [-t/--to] is who this will greet
248+
from_: [-f/] the sender of these greetings
249+
name: [-t/--to] the receiver of these greetings
248250
"""
249251
print(f"Hello, {name}!")
250-
print(f"From: {', '.join(from_)}")
252+
print(f"From: {from_}")
251253
```
252254

253255
```console
254-
user@machine:~$ python3 hello-6.py -h
255-
usage: hello-6.py [-h] [-t TO] [from ...]
256+
user@machine:~$ python3 etc/scripts/hello-6.py -h
257+
usage: hello-6.py [-h] [-f FROM] [-t TO]
256258

257259
this will say hello to someone
258260

259-
positional arguments:
260-
from greetings are sent from these people (type: str)
261-
262261
options:
263262
-h, --help show this help message and exit
264-
-t, --to TO is who this will greet (type: str, default: world)
263+
-f FROM the sender of these greetings (type: str, default: me)
264+
-t, --to TO the receiver of these greetings (type: str, default: world)
265265
```
266266

267267
### Metavars
@@ -282,37 +282,35 @@ tuple length.
282282

283283
```python
284284
@arguably.command
285-
def hello(*from_, name="world"):
285+
def hello(*, from_="me", name="world"):
286286
"""
287287
this will say hello to someone
288288
289289
Args:
290-
from_: greetings are sent from these people
291-
name: [-t/--to] is {who} this will greet
290+
from_: [-f/] the {sender} of these greetings
291+
name: [-t/--to] the {receiver} of these greetings
292292
"""
293293
print(f"Hello, {name}!")
294-
print(f"From: {', '.join(from_)}")
294+
print(f"From: {from_}")
295295
```
296296

297297
```console
298-
user@machine:~$ python3 hello-7.py -h
299-
usage: hello-7.py [-h] [-t WHO] [from ...]
298+
user@machine:~$ python3 etc/scripts/hello-7.py -h
299+
usage: hello-7.py [-h] [-f SENDER] [-t RECEIVER]
300300

301301
this will say hello to someone
302302

303-
positional arguments:
304-
from greetings are sent from these people (type: str)
305-
306303
options:
307-
-h, --help show this help message and exit
308-
-t, --to WHO is who this will greet (type: str, default: world)
304+
-h, --help show this help message and exit
305+
-f SENDER the sender of these greetings (type: str, default: me)
306+
-t, --to RECEIVER the receiver of these greetings (type: str, default: world)
309307
```
310308

311309
Compare the last line with how it was before:
312310

313311
```console
314-
Before: -t, --to TO is who this will greet (type: str, default: world)
315-
After: -t, --to WHO is who this will greet (type: str, default: world)
312+
Before: -t, --to TO the receiver of these greetings (type: str, default: world)
313+
After: -t, --to RECEIVER the receiver of these greetings (type: str, default: world)
316314
```
317315

318316
## Summary
@@ -340,5 +338,9 @@ usage: intro.py [-h] [-x OPTION] required [not-required] [others ...]
340338

341339
Docstrings are used for command and argument help messages. They can also:
342340

343-
* Change the short (`-n`) and long name (`--name`) of an `--option` by prefixing its description with `[-n/--name]`
341+
* Change option names:
342+
* Set the short name with `[-n]`
343+
* Change the long name with `[--name]`
344+
* Set the short and long names with `[-n/--name]`
345+
* Set the short name and remove the long name with `[-n/]`
344346
* Change the metavar of an argument to `SOMETHING` by wrapping a word in curly braces: `{something}`

etc/scripts/hello-6.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import arguably
22

33
@arguably.command
4-
def hello(*from_, name="world"):
4+
def hello(*, from_="me", name="world"):
55
"""
66
this will say hello to someone
77
88
Args:
9-
from_: greetings are sent from these people
10-
name: [-t/--to] is who this will greet
9+
from_: [-f/] the sender of these greetings
10+
name: [-t/--to] the receiver of these greetings
1111
"""
1212
print(f"Hello, {name}!")
13-
print(f"From: {', '.join(from_)}")
13+
print(f"From: {from_}")
1414

1515
if __name__ == "__main__":
1616
arguably.run()

etc/scripts/hello-7.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import arguably
22

33
@arguably.command
4-
def hello(*from_, name="world"):
4+
def hello(*, from_="me", name="world"):
55
"""
66
this will say hello to someone
77
88
Args:
9-
from_: greetings are sent from these people
10-
name: [-t/--to] is {who} this will greet
9+
from_: [-f/] the {sender} of these greetings
10+
name: [-t/--to] the {receiver} of these greetings
1111
"""
1212
print(f"Hello, {name}!")
13-
print(f"From: {', '.join(from_)}")
13+
print(f"From: {from_}")
1414

1515
if __name__ == "__main__":
1616
arguably.run()

0 commit comments

Comments
 (0)