Skip to content

Commit acbf0bc

Browse files
Improve docs for CLI commands (#32)
* docs: dynamic list of commands * docs: strip ansi escape sequences from jobby help * docs: improve gb2gtf help message * chore: update CHANGELOG.md * ci: 🤖 render readme --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent a1208c6 commit acbf0bc

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- fix docstrings rendering -- use Google style. (#25, @kelly-sovacool)
1313
- overhaul navigation structure of docs website. (#28, @kelly-sovacool)
1414
- style the website to follow FNL branding guidelines. (#30, @kelly-sovacool)
15+
- miscellaneous minor improvements. (#32, @kelly-sovacool)
1516
- bug fixes:
1617
- include data files in package installation for `homologfinder`. (#31, @kelly-sovacool)
1718

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ ccbr_tools --help
4747

4848
For more options, run: ccbr_tools [command] --help
4949

50+
https://ccbr.github.io/Tools/
51+
5052
Options:
5153
-v, --version Show the version and exit.
5254
-h, --help Show this message and exit.

docs/cli.qmd

+16-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ subtitle: CLI utilities in CCBR Tools
99
#| echo: false
1010
#| output: asis
1111
from ccbr_tools.shell import shell_run
12+
help_msg = shell_run("ccbr_tools --help")
1213
print("```")
13-
print(shell_run("ccbr_tools --help"))
14+
print(help_msg)
1415
print("```", end = '\n\n')
1516
16-
for cmd in ('cite', 'send-email', 'version'):
17+
# get list of ccbr_tools commands from the help message
18+
help_lst = help_msg.split('\n\n')
19+
commands_idx = [idx for idx,ele in enumerate(help_lst) if ele.startswith('Commands:')][0]
20+
commands = [cmd.split()[0] for cmd in help_lst[commands_idx].split('\n')[1:]]
21+
for cmd in commands:
1722
print(f"### {cmd}", end = '\n\n')
1823
print("```")
1924
print(shell_run(f"ccbr_tools {cmd} --help"))
@@ -26,11 +31,19 @@ for cmd in ('cite', 'send-email', 'version'):
2631
```{python}
2732
#| echo: false
2833
#| output: asis
34+
import re
2935
from ccbr_tools.pkg_util import get_project_scripts
36+
37+
# https://stackoverflow.com/a/14693789/5787827
38+
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
39+
3040
for cmd in get_project_scripts():
3141
if cmd != 'ccbr_tools':
3242
print(f"### {cmd}", end = '\n\n')
3343
print("```")
34-
print(shell_run(f"{cmd} --help"))
44+
help_msg = shell_run(f"{cmd} --help")
45+
if cmd == 'jobby':
46+
help_msg = ansi_escape.sub('', help_msg)
47+
print(help_msg)
3548
print("```", end = '\n\n')
3649
```

src/ccbr_tools/__main__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
from .templates import use_quarto_ext, get_quarto_extensions
1717

1818

19-
all_commands = "All installed tools:\n" + "\n".join(
19+
all_scripts = "All installed tools:\n" + "\n".join(
2020
[f" {cmd}" for cmd in get_project_scripts()]
2121
)
2222

2323

2424
@click.group(
2525
cls=CustomClickGroup,
2626
context_settings=dict(help_option_names=["-h", "--help"]),
27-
epilog=all_commands,
27+
epilog=all_scripts,
2828
)
2929
@click.version_option(get_version(), "-v", "--version", is_flag=True)
3030
def cli():
@@ -34,6 +34,7 @@ def cli():
3434
For more options, run:
3535
ccbr_tools [command] --help
3636
37+
https://ccbr.github.io/Tools/
3738
"""
3839
pass
3940

src/ccbr_tools/gb2gtf.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ def main():
2121
gb2gtf(sys.argv)
2222

2323

24+
usage_msg = """Convert GenBank files to GTF format.
25+
26+
Usage: gb2gtf sequence.gb > sequence.gtf
27+
"""
28+
29+
2430
def check_args(args):
2531
valid_usage = True
2632
if len(args) < 2 or "-h" in args or "--help" in args:
27-
print("Usage: gb2gtf sequence.gb > sequence.gtf")
33+
print(usage_msg)
2834
valid_usage = False
2935
return valid_usage
3036

0 commit comments

Comments
 (0)