Skip to content

Commit

Permalink
Improve docs for CLI commands (#32)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kelly-sovacool and github-actions[bot] authored Jan 9, 2025
1 parent a1208c6 commit acbf0bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- fix docstrings rendering -- use Google style. (#25, @kelly-sovacool)
- overhaul navigation structure of docs website. (#28, @kelly-sovacool)
- style the website to follow FNL branding guidelines. (#30, @kelly-sovacool)
- miscellaneous minor improvements. (#32, @kelly-sovacool)
- bug fixes:
- include data files in package installation for `homologfinder`. (#31, @kelly-sovacool)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ ccbr_tools --help

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

https://ccbr.github.io/Tools/

Options:
-v, --version Show the version and exit.
-h, --help Show this message and exit.
Expand Down
19 changes: 16 additions & 3 deletions docs/cli.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ subtitle: CLI utilities in CCBR Tools
#| echo: false
#| output: asis
from ccbr_tools.shell import shell_run
help_msg = shell_run("ccbr_tools --help")
print("```")
print(shell_run("ccbr_tools --help"))
print(help_msg)
print("```", end = '\n\n')
for cmd in ('cite', 'send-email', 'version'):
# get list of ccbr_tools commands from the help message
help_lst = help_msg.split('\n\n')
commands_idx = [idx for idx,ele in enumerate(help_lst) if ele.startswith('Commands:')][0]
commands = [cmd.split()[0] for cmd in help_lst[commands_idx].split('\n')[1:]]
for cmd in commands:
print(f"### {cmd}", end = '\n\n')
print("```")
print(shell_run(f"ccbr_tools {cmd} --help"))
Expand All @@ -26,11 +31,19 @@ for cmd in ('cite', 'send-email', 'version'):
```{python}
#| echo: false
#| output: asis
import re
from ccbr_tools.pkg_util import get_project_scripts
# https://stackoverflow.com/a/14693789/5787827
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
for cmd in get_project_scripts():
if cmd != 'ccbr_tools':
print(f"### {cmd}", end = '\n\n')
print("```")
print(shell_run(f"{cmd} --help"))
help_msg = shell_run(f"{cmd} --help")
if cmd == 'jobby':
help_msg = ansi_escape.sub('', help_msg)
print(help_msg)
print("```", end = '\n\n')
```
5 changes: 3 additions & 2 deletions src/ccbr_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from .templates import use_quarto_ext, get_quarto_extensions


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


@click.group(
cls=CustomClickGroup,
context_settings=dict(help_option_names=["-h", "--help"]),
epilog=all_commands,
epilog=all_scripts,
)
@click.version_option(get_version(), "-v", "--version", is_flag=True)
def cli():
Expand All @@ -34,6 +34,7 @@ def cli():
For more options, run:
ccbr_tools [command] --help
https://ccbr.github.io/Tools/
"""
pass

Expand Down
8 changes: 7 additions & 1 deletion src/ccbr_tools/gb2gtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ def main():
gb2gtf(sys.argv)


usage_msg = """Convert GenBank files to GTF format.
Usage: gb2gtf sequence.gb > sequence.gtf
"""


def check_args(args):
valid_usage = True
if len(args) < 2 or "-h" in args or "--help" in args:
print("Usage: gb2gtf sequence.gb > sequence.gtf")
print(usage_msg)
valid_usage = False
return valid_usage

Expand Down

0 comments on commit acbf0bc

Please sign in to comment.