Skip to content

Commit c2d1527

Browse files
committed
docs: misc consistency & tidy
1 parent aa681d6 commit c2d1527

4 files changed

Lines changed: 25 additions & 23 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
args: [-i]
2626
entry: TODO
2727
types: [text]
28-
exclude: ^(.pre-commit-config.yaml|.github/workflows/test.yml)$
28+
exclude: ^.pre-commit-config.yaml$
2929
- id: pytest
3030
name: pytest
3131
language: python

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Features
2929
- `click <https://pypi.org/project/click>`_
3030

3131
- ``<arguments>``, ``--options`` and ``sub commands``
32-
- Choices (``--say={hello,goodbye}```)
32+
- Choices (``--say={hello,goodbye}``)
3333
- Paths (``--file={*.y*ml,*.toml}``, ``--dir=*/``)
3434
- Dynamic shell commands (``--branch=$(git branch)``)
3535

‎docs/index.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ follow the OS-specific instructions below.
9292

9393
## FAQs
9494

95-
Not working?
96-
9795
- Ensure that `shtab` and the application you're trying to complete are both accessible from your environment.
98-
- Ensure that `prog` is set:
99-
- if using [`options.entry_points.console_scripts=MY_PROG=...`](https://setuptools.pypa.io/en/latest/userguide/entry_point.html), then ensure the main parser's `prog` matches `argparse.ArgumentParser(prog="MY_PROG")` or override it using `shtab MY_PROG.get_main_parser --prog=MY_PROG`.
100-
- if executing a script file `./MY_PROG.py` (with a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) `#!/usr/bin/env python`) directly, then use `argparse.ArgumentParser(prog="MY_PROG.py")` or override it using `shtab MY_PROG.get_main_parser --prog=MY_PROG.py`.
101-
- Any argument with `help=argparse.SUPPRESS` is skipped.
96+
- Ensure that `prog` matches the executable name:
97+
- if using [`project.scripts.MY-PROG=...`](https://setuptools.pypa.io/en/latest/userguide/entry_point.html), then
98+
- set the main parser's name (`argparse.ArgumentParser(prog="MY-PROG")`, `argopt(prog="MY-PROG")`, `click.group("MY-PROG")`, `click.command("MY-PROG")`, etc)
99+
- or override it using `shtab MY_PROG.get_main_parser --prog=MY-PROG`
100+
- if executing a script file `./MY_PROG.py` (with a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) `#!/usr/bin/env python`) directly, then use `prog="MY_PROG.py"`
101+
- Any suppressed argument (`help=argparse.SUPPRESS`, click `hidden=True`/`deprecated=True`) is skipped.
102102
- Default completion (when no choices are specified) is disabled. Enable it explicitly via e.g. `parser.add_argument('positional').complete = shtab.FILE`.
103103
- Some shells (e.g. `zsh`, `fish`) print information during tab completion:
104-
- subparser `description` takes precedence over `help`.
105-
- argument `metavar` takes precedence over `dest`.
104+
- subparser `description` takes precedence over `help`
105+
- argument `metavar` takes precedence over `dest`
106106
- [Ask a general question on StackOverflow](https://stackoverflow.com/questions/tagged/shtab).
107107
- [Report bugs and open feature requests on GitHub][issues].
108108

‎docs/use.md‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Below are various examples of enabling `shtab`'s own tab completion scripts.
103103
| sudo tee /usr/share/fish/vendor_completions.d/shtab.fish
104104
```
105105

106+
### argparse
107+
106108
Any existing `argparse`-based scripts should be supported with minimal effort.
107109
For example, starting with this existing code:
108110

@@ -111,7 +113,7 @@ For example, starting with this existing code:
111113
import argparse
112114

113115
def get_main_parser():
114-
parser = argparse.ArgumentParser(prog="MY_PROG", ...)
116+
parser = argparse.ArgumentParser(prog="MY-PROG", ...)
115117
parser.add_argument(...)
116118
parser.add_subparsers(...)
117119
...
@@ -123,39 +125,39 @@ if __name__ == '__main__':
123125
...
124126
```
125127

126-
Assuming this code example is installed in `MY_PROG.command.main`, simply run:
128+
Assuming this code example is installed in `MY_PROG.cli`, simply run:
127129

128130
=== "bash"
129131

130132
```sh
131-
shtab --shell=bash -u MY_PROG.command.main.get_main_parser \
132-
| sudo tee /etc/bash_completion.d/MY_PROG
133+
shtab --shell=bash -u MY_PROG.cli.get_main_parser \
134+
| sudo tee /etc/bash_completion.d/MY-PROG
133135
```
134136

135137
=== "zsh"
136138

137139
```sh
138-
shtab --shell=zsh -u MY_PROG.command.main.get_main_parser \
139-
| sudo tee /usr/local/share/zsh/site-functions/_MY_PROG
140+
shtab --shell=zsh -u MY_PROG.cli.get_main_parser \
141+
| sudo tee /usr/local/share/zsh/site-functions/_MY-PROG
140142
```
141143

142144
=== "tcsh"
143145

144146
```sh
145-
shtab --shell=tcsh -u MY_PROG.command.main.get_main_parser \
146-
| sudo tee /etc/profile.d/MY_PROG.completion.csh
147+
shtab --shell=tcsh -u MY_PROG.cli.get_main_parser \
148+
| sudo tee /etc/profile.d/MY-PROG.completion.csh
147149
```
148150

149151
=== "fish"
150152

151153
```sh
152-
shtab --shell=fish -u MY_PROG.command.main.get_main_parser \
153-
| sudo tee /usr/share/fish/vendor_completions.d/MY_PROG.fish
154+
shtab --shell=fish -u MY_PROG.cli.get_main_parser \
155+
| sudo tee /usr/share/fish/vendor_completions.d/MY-PROG.fish
154156
```
155157

156158
### click
157159

158-
Speedup `click`'s completions (and get support for more shell types) by changing from e.g. `_MY_PROG_COMPLETE=bash_source my-prog` to `shtab my_prog.cli.cli --prog my-prog -s bash`
160+
Speedup `click`'s completions (and get support for more shell types) by changing from e.g. `_MY_PROG_COMPLETE=bash_source MY-PROG` to `shtab MY_PROG.cli.main --prog MY-PROG -s bash`
159161

160162
## Library Usage
161163

@@ -229,7 +231,7 @@ Add direct support to scripts for a little more configurability:
229231
main()
230232
```
231233

232-
=== "click"
234+
=== "click.command"
233235

234236
```{.py title="click_process.py" linenums="1" hl_lines="5"}
235237
#!/usr/bin/env python
@@ -249,7 +251,7 @@ Add direct support to scripts for a little more configurability:
249251
process()
250252
```
251253

252-
=== "click (group/subcommand)"
254+
=== "click.group"
253255

254256
```{.py title="click_subcommand.py" linenums="1" hl_lines="17"}
255257
#!/usr/bin/env python

0 commit comments

Comments
 (0)