Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --version and auto-update README (enforced) #57

Merged
merged 8 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/readme-updated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check README.md helptext

on:
push:
branches:
- main
pull_request:
branches: [main]

jobs:
check_script_and_diff:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install duct
run: |
pip install .

- name: Update README.md helptext
run: |
./.update-readme-help.sh

- name: Ensure no diff
run: |
git diff --exit-code
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ repos:
rev: v2.2.6
hooks:
- id: codespell
- repo: local
hooks:
- id: update-readme
name: Update README with --help output
entry: ./.update-readme-help.sh
language: system
5 changes: 5 additions & 0 deletions .update-readme-help.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
duct --help > .help_content.txt
sed -i '/<\!--- BEGIN HELP -->/,/<\!--- END HELP -->/{//!d;}' README.md
sed -i '/<\!--- BEGIN HELP -->/r .help_content.txt' README.md
rm .help_content.txt
14 changes: 14 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ The following pull request labels are respected:
* performance: Improve performance of an existing feature


Precommit
---------

The project uses a number of automated checks to limit tedious work.
The checks will be run automatically prior to commit if `pre-commit` is installed in your
environment.

`pip install pre-commit`

Note: the README.md is automatically updated to include the helptext, but because argparse changed its
output in python 3.10+, CI enforces the 3.10+ helptext.
Please either use 3.10+ or drop the `optional arguments` vs `options` diff.


Testing
-------
If you are contributing code, please consider adding a unit test.
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ A process wrapper script that monitors the execution of a command.
```shell
> duct --help

usage: duct [-h] [-p OUTPUT_PREFIX] [--sample-interval SAMPLE_INTERVAL]
<!--- BEGIN HELP -->
usage: duct [-h] [--version] [-p OUTPUT_PREFIX]
[--sample-interval SAMPLE_INTERVAL]
[--report-interval REPORT_INTERVAL] [-c {all,none,stdout,stderr}]
[-o {all,none,stdout,stderr}]
[-t {all,system-summary,processes-samples}]
command [arguments ...]
command [command_args ...] ...

Gathers metrics on a command and all its child processes.

positional arguments:
command The command to execute.
arguments Arguments for the command. (default: None)
command [command_args ...]
The command to execute, along with its arguments.
command_args Arguments for the command.

options:
-h, --help show this help message and exit
--version show program's version number and exit
-p OUTPUT_PREFIX, --output-prefix OUTPUT_PREFIX
File string format to be used as a prefix for the
files -- the captured stdout and stderr and the
Expand Down Expand Up @@ -50,6 +54,7 @@ options:
-t {all,system-summary,processes-samples}, --record-types {all,system-summary,processes-samples}
Record system-summary, processes-samples, or all
(default: all)
<!--- END HELP -->
```

## Testing:
Expand Down
11 changes: 9 additions & 2 deletions src/duct.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,16 @@ def create_and_parse_args():
description="Gathers metrics on a command and all its child processes.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("command", help="The command to execute.")
parser.add_argument(
"inner_args", nargs=argparse.REMAINDER, help="Arguments for the command."
"command",
metavar="command [command_args ...]",
help="The command to execute, along with its arguments.",
)
parser.add_argument(
"--version", action="version", version=f"%(prog)s {__version__}"
)
parser.add_argument(
"command_args", nargs=argparse.REMAINDER, help="Arguments for the command."
)
parser.add_argument(
"-p",
Expand Down
Loading