Skip to content

Commit

Permalink
Merge pull request #10 from evgenyz/main
Browse files Browse the repository at this point in the history
Polish modules arguments
  • Loading branch information
jan-cerny authored Jun 28, 2024
2 parents 42d2287 + 0b4d254 commit aef2c28
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 43 deletions.
6 changes: 1 addition & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ root = true
end_of_line = lf
insert_final_newline = true


[**/make.bat]
end_of_line = crlf

[**.py]
indent_size = unset
tab_width = 4
indent_style = space

max_line_length = 99

[{**.yml,**.yaml}]
indent_size = 4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# compliance-tool
# Compliance Tool

[![Documentation Status](https://readthedocs.org/projects/compliance-tool/badge/?version=latest)](https://compliance-tool.readthedocs.io/en/latest/?badge=latest)
[![Maintainability](https://api.codeclimate.com/v1/badges/a7262d19c1745a48659f/maintainability)](https://codeclimate.com/github/ComplianceAsCode/compliance-tool/maintainability)
92 changes: 56 additions & 36 deletions compliance_tool/cli.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,77 @@
import argparse
from compliance_tool import list, scan, remediate
from compliance_tool import list_, scan, remediate


def prepare_parser_list(subparsers) -> None:
parser = subparsers.add_parser("list",
help="list available components")
parser.set_defaults(func=list.execute)
list_subparsers = parser.add_subparsers(required=True)
def prepare_parser_list(cli_sub_parsers, global_parser, profile_parser) -> None:
parser = cli_sub_parsers.add_parser("list", parents=[global_parser],
help="list available components"
" (profiles, rules, controls),"
" will list profiles if component type"
" is not specified")
# TODO: Set individual functions for sub-parsers to distinguish between listing modes
# this one should be linked with listing profiles as we consider it to
# be the default listing operation.
parser.set_defaults(func=list_.execute)
list_subparsers = parser.add_subparsers(required=False)

list_subparsers.add_parser("profiles",
help="list available profiles")

parser = list_subparsers.add_parser("controls",
help="list available controls for a given profile")
parser.add_argument("--profile")
list_subparsers.add_parser("controls", parents=[profile_parser],
help="list available controls (requirements)"
" within a given profile")

parser = list_subparsers.add_parser("rules",
help="list available rules for a given profile")
parser.add_argument("--profile")
list_subparsers.add_parser("rules", parents=[profile_parser],
help="list available rules for a given profile")


def prepare_parser_scan(subparsers) -> None:
parser = subparsers.add_parser("scan",
help="perform a compliance scan")
def prepare_parser_scan(cli_sub_parsers, global_parser, profile_parser) -> None:
parser = cli_sub_parsers.add_parser("scan", parents=[global_parser, profile_parser],
help="perform a compliance scan")
parser.set_defaults(func=scan.execute)
parser.add_argument("--profile")
parser.add_argument("--control")
parser.add_argument("--rule")

parser.add_argument("--html")
parser.add_argument("--json")
parser.add_argument("--control", metavar="CONTROL_ID",
help="use only control(s) (requirement(s)) with given identifier")
parser.add_argument("--rule", metavar="RULE_ID",
help="use only rule(s) with given identifier")

parser.add_argument("--html", metavar="DESTINATION_FILE",
help="write a human-readable HTML report with the results"
" at the given destination")
parser.add_argument("--json", metavar="DESTINATION_FILE",
help="write a JSON-formatted report with the results"
" at the given destination")

def prepare_parser_remediate(subparsers) -> None:
parser = subparsers.add_parser("remediate",
help="perform a system remediation")

def prepare_parser_remediate(cli_sub_parsers, global_parser, profile_parser) -> None:
parser = cli_sub_parsers.add_parser("remediate", parents=[global_parser, profile_parser],
help="perform a system remediation")
parser.set_defaults(func=remediate.execute)
parser.add_argument("--profile")
parser.add_argument("--control")
parser.add_argument("--rule")

parser.add_argument("--control", metavar="CONTROL_ID",
help="control (requirement) identifier")
parser.add_argument("--rule", metavar="RULE_ID",
help="rule identifier")


def prepare_parsers() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True)
parser.add_argument("--input",
help="policy definitions (file)")
parser.add_argument("--tailoring",
help="policy tailoring customization (file)")
prepare_parser_list(subparsers)
prepare_parser_scan(subparsers)
prepare_parser_remediate(subparsers)
return parser
global_parser = argparse.ArgumentParser(add_help=False)
global_parser.add_argument("--tailoring", metavar="SOURCE_FILE",
help="policy customizations"
" (recognized formats: JSON Tailoring)")

profile_parser = argparse.ArgumentParser(add_help=False)
profile_parser.add_argument("--profile", metavar="PROFILE_ID",
required=True,
help="identifier of the profile that should be used"
" for selected operation")

cli_parser = argparse.ArgumentParser()
cli_sub_parsers = cli_parser.add_subparsers(required=True)
prepare_parser_list(cli_sub_parsers, global_parser, profile_parser)
prepare_parser_scan(cli_sub_parsers, global_parser, profile_parser)
prepare_parser_remediate(cli_sub_parsers, global_parser, profile_parser)
return cli_parser


def main() -> int:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'compliance-tool'
project = 'Compliance Tool'
copyright = '2024, ComplianceAsCode'
author = 'ComplianceAsCode'

Expand Down

0 comments on commit aef2c28

Please sign in to comment.