Skip to content

Commit 6c52f87

Browse files
committed
use sub-commands.
1 parent b1be748 commit 6c52f87

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

Tests/kaas/sonobuoy_handler/run_sonobuoy.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@
1111
logger = logging.getLogger(__name__)
1212

1313

14-
@click.command()
15-
@click.option("-k", "--kubeconfig", "kubeconfig", required=False, type=click.Path(exists=True), help="path/to/kubeconfig_file.yaml",)
14+
@click.group()
15+
def cli():
16+
pass
17+
18+
19+
@cli.command("run")
20+
@click.option("-k", "--kubeconfig", "kubeconfig", required=True, type=click.Path(exists=True), help="path/to/kubeconfig_file.yaml",)
1621
@click.option("-r", "--result_dir_name", "result_dir_name", type=str, default="sonobuoy_results", help="directory name to store results at",)
1722
@click.option("-c", "--check", "check_name", type=str, default="sonobuoy_executor", help="this MUST be the same name as the id in 'scs-compatible-kaas.yaml'",)
18-
@click.option("--sonobuoy-config", "sonobuoy_config", type=click.Path(exists=True), default="kaas/sonobuoy-config.yaml", help="Configuration for Sonobuoy (yaml format)")
19-
@click.option("--sonobuoy-result-yaml", "sonobuoy_result_yaml", type=click.Path(exists=True), default="", help="Test the provided sonobuoy result yaml file. Sonobuoy will not be executed!")
23+
@click.option("--sonobuoy-config", "sonobuoy_config_yaml", type=click.Path(exists=True), default="kaas/sonobuoy-config.yaml", help="Configuration for Sonobuoy (yaml format)")
2024
@click.option("-a", "--arg", "args", multiple=True)
21-
def sonobuoy_run(kubeconfig, result_dir_name, check_name, sonobuoy_config, sonobuoy_result_yaml, args):
22-
if sonobuoy_result_yaml:
23-
check_sonobuoy_result(sonobuoy_config, sonobuoy_result_yaml)
24-
sys.exit(0)
25-
if not kubeconfig:
26-
raise click.UsageError("--kubeconfig/-k is required unless --sonobuoy-result-yaml is provided")
27-
sonobuoy_handler = SonobuoyHandler(check_name, kubeconfig, result_dir_name, sonobuoy_config, args)
25+
def sonobuoy_run(kubeconfig, result_dir_name, check_name, sonobuoy_config_yaml, args):
26+
sonobuoy_handler = SonobuoyHandler(check_name, kubeconfig, result_dir_name, sonobuoy_config_yaml, args)
2827
sys.exit(sonobuoy_handler.run())
2928

3029

30+
@cli.command("check-results")
31+
@click.argument("sonobuoy_config_yaml", type=click.Path(exists=True))
32+
@click.argument("sonobuoy_result_yaml", type=click.Path(exists=True))
33+
def check_results(sonobuoy_config_yaml, sonobuoy_result_yaml):
34+
check_sonobuoy_result(sonobuoy_config_yaml, sonobuoy_result_yaml)
35+
sys.exit(0)
36+
37+
3138
if __name__ == "__main__":
3239
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
33-
sonobuoy_run()
40+
cli()

0 commit comments

Comments
 (0)