Skip to content

Commit

Permalink
separate clearlydefined commands into two subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmehl committed Aug 13, 2024
1 parent ebfc3fc commit 5722ac5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ For each command, you can get detailed options, e.g. `compliance-assistant sbom
* Create an SBOM for the current directory: `compliance-assistant sbom generate -d .`
* Enrich an SBOM with ClearlyDefined data: `compliance-assistant sbom enrich -f /tmp/my-sbom.json -o /tmp/my-enriched-sbom.json`
* Extract certain data from an SBOM: `compliance-assistant sbom parse -f /tmp/my-enriched-sbom.json -e purl,copyright,name`
* Gather ClearlyDefined licensing/copyright information for one package: `compliance-assistant clearlydefined -p pkg:pypi/inwx-dns-recordmaster@0.3.1`
* Gather ClearlyDefined licensing/copyright information for one package: `compliance-assistant clearlydefined fetch -p pkg:pypi/inwx-dns-recordmaster@0.3.1`
* Get license outbound candidate based on licenses from SBOM: `compliance-assistant licensing outbound -f /tmp/my-enriched-sbom.json`

### Run as GitHub workflow
Expand Down
52 changes: 35 additions & 17 deletions complassist/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,50 @@
# ClearlyDefined
parser_cd = subparsers.add_parser(
"clearlydefined",
help="Gather license information from ClearlyDefined for a package",
help="Use ClearlyDefined to fetch licensing and copyright information, and run coversions",
)
subparser_cd = parser_cd.add_subparsers(
dest="clearlydefined_command",
help="Available clearlydefined commands",
)

# ClearlyDefined convert subcommand
parser_cd_convert = subparser_cd.add_parser(
"convert",
help="Convert a Package URL to ClearlyDefined coordinates",
parents=[common_flags],
)
parser_cd_exclusive = parser_cd.add_mutually_exclusive_group(required=True)
parser_cd_exclusive.add_argument(
parser_cd_convert.add_argument(
"-p",
"--purl",
help="A Package URL (purl) to convert to ClearlyDefined coordinates.",
)

# ClearlyDefined fetch subcommand
parser_cd_fetch = subparser_cd.add_parser(
"fetch",
help="Fetch licensing and copyright information of packages from ClearlyDefined",
parents=[common_flags],
)
parser_cd_fetch_exclusive = parser_cd_fetch.add_mutually_exclusive_group(required=True)
parser_cd_fetch_exclusive.add_argument(
"-p",
"--purl",
help=(
"The purl for which ClearlyDefined licensing information is searched. "
"If -c is used, this is preferred."
"Cannot be combined with -c"
),
)
parser_cd_exclusive.add_argument(
parser_cd_fetch_exclusive.add_argument(
"-c",
"--coordinates",
help=(
"The ClearlyDefined coordinates for which ClearlyDefined licensing information is searched"
),
)
parser_cd_exclusive.add_argument(
"--purl-to-coordinates",
help=(
"Convert a Package URL (purl) to ClearlyDefined coordinates, and show result. "
"Cannot be combined with -p and -c."
"The ClearlyDefined coordinates for which licensing information is searched. "
"Canot be combined with -p."
),
)


# License Compliance
parser_licensing = subparsers.add_parser(
"licensing",
Expand Down Expand Up @@ -259,12 +276,13 @@ def main(): # pylint: disable=too-many-branches, too-many-statements
else:
parser_sbom.print_help()

# Get ClearlyDefined license/copyright data for a package
# ClearlyDefined commands
elif args.command == "clearlydefined":
if args.purl_to_coordinates:
print(purl_to_cd_coordinates(args.purl_to_coordinates))
# ClearlyDefined conversion
if args.clearlydefined_command == "convert":
print(purl_to_cd_coordinates(args.purl))

elif args.coordinates or args.purl:
elif args.clearlydefined_command == "fetch":
if args.purl:
coordinates = purl_to_cd_coordinates(args.purl)
else:
Expand Down

0 comments on commit 5722ac5

Please sign in to comment.