Skip to content

Commit

Permalink
make -v available for all subcommands directly, feels more natural th…
Browse files Browse the repository at this point in the history
…is way
  • Loading branch information
mxmehl committed Aug 13, 2024
1 parent 37c3e46 commit ebfc3fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ compliance-assistant
poetry run compliance-assistant
```

In the following, we will just use `compliance-assistant`
In the following, we will just use `compliance-assistant`.

### Command Structure

```bash
compliance-assistant [global-options] <command> [command-options]
compliance-assistant <command> [<subcommand>] [subcommand-options]
```

### Commands

Please run `compliance-assistant --help` to get an overview of the commands and global options.

For each command, you can get detailed options, e.g. `compliance-assistant sbom-enrich --help`.
For each command, you can get detailed options, e.g. `compliance-assistant sbom enrich --help`.

### Examples

Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
path: ${{ runner.temp }}
# Run compliance-assistant sbom-enrich
- name: Enrich SBOM
run: compliance-assistant sbom-enrich -f ${{ runner.temp }}/sbom-raw.json -o ${{ runner.temp }}/sbom-enriched.json
run: compliance-assistant sbom enrich -f ${{ runner.temp }}/sbom-raw.json -o ${{ runner.temp }}/sbom-enriched.json
# Upload enriched SBOM as artifact
- name: Store enriched SBOM as artifact
uses: actions/upload-artifact@v4
Expand Down
16 changes: 12 additions & 4 deletions complassist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
from ._sbom_generate import generate_cdx_sbom
from ._sbom_parse import extract_items_from_cdx_sbom

# Main parser with root-level flags
parser = argparse.ArgumentParser(description=__doc__)

# General flags
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
parser.add_argument("--version", action="version", version="%(prog)s " + __version__)

# Subcommands
# Initiate first-level subcommands
subparsers = parser.add_subparsers(dest="command", help="Available commands", required=True)

# Common flags, usable for all effective subcommands
common_flags = argparse.ArgumentParser(add_help=False) # No automatic help to avoid duplication
common_flags.add_argument("-v", "--verbose", action="store_true", help="Verbose output")

# SBOM commands
parser_sbom = subparsers.add_parser(
"sbom",
Expand All @@ -47,6 +49,7 @@
parser_sbom_gen = subparser_sbom.add_parser(
"generate",
help="Generate a CycloneDX SBOM using the cdxgen Docker image",
parents=[common_flags],
)
parser_sbom_gen.add_argument(
"-d",
Expand All @@ -67,6 +70,7 @@
parser_sbom_enrich = subparser_sbom.add_parser(
"enrich",
help="Enrich a CycloneDX SBOM and its licensing/copyright data via ClearlyDefined",
parents=[common_flags],
)
parser_sbom_enrich.add_argument(
"-f",
Expand All @@ -86,6 +90,7 @@
"parse",
help="Parse a CycloneDX SBOM and extract contained information",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[common_flags],
)
parser_sbom_read.add_argument(
"-f",
Expand Down Expand Up @@ -116,6 +121,7 @@
parser_cd = subparsers.add_parser(
"clearlydefined",
help="Gather license information from ClearlyDefined for a package",
parents=[common_flags],
)
parser_cd_exclusive = parser_cd.add_mutually_exclusive_group(required=True)
parser_cd_exclusive.add_argument(
Expand Down Expand Up @@ -155,6 +161,7 @@
parser_licensing_list = subparser_licensing.add_parser(
"list",
help="List all detected licenses",
parents=[common_flags],
)
parser_licensing_list.add_argument(
"-f",
Expand All @@ -179,6 +186,7 @@
parser_licensing_outbound = subparser_licensing.add_parser(
"outbound",
help="Suggest possible outbound licenses based on found licenses in an SBOM",
parents=[common_flags],
)
parser_licensing_outbound.add_argument(
"-f",
Expand Down

0 comments on commit ebfc3fc

Please sign in to comment.