diff --git a/harpy/view.py b/harpy/view.py index 48b2f1c8e..7774f08f8 100644 --- a/harpy/view.py +++ b/harpy/view.py @@ -1,4 +1,4 @@ -"""View the latest log or snakefile of a workflow""" +"""View the latest log, config, or snakefile of a workflow""" import os import sys @@ -9,15 +9,16 @@ from ._validations import is_gzip @click.command(no_args_is_help = True, context_settings=dict(allow_interspersed_args=False)) -@click.option('-s', '--snakefile', is_flag = True, show_default = True, default = False, help = "View the snakefile, not the log file") +@click.option('-s', '--snakefile', is_flag = True, show_default = True, default = False, help = "View the snakefile instead") +@click.option('-c', '--config', is_flag = True, show_default = True, default = False, help = "View the workflow config file instead") @click.argument('directory', required=True, type=click.Path(exists=True, file_okay=False)) -def view(directory, snakefile): +def view(directory, snakefile, config): """ - View a workflow log file or snakefile + View a workflow log, config, or snakefile This convenience command lets you view the latest workflow log file - of a Harpy output directory. You can use `--snakefile` to view the workflow - snakefile instead. Output is printed to the screen via `less` and + of a Harpy output directory. Use `--snakefile` or `--config` to view the workflow + snakefile or config.yaml file instead, respectively. Output is printed to the screen via `less` and accepts the typical keyboard shortcuts to navigate the output, e.g.: | key | function | @@ -28,19 +29,30 @@ def view(directory, snakefile): """ # check if there is a workflow or log folder # and whether the expected files are in there + if snakefile and config: + print_error("Invalid options", "Please pick one of [bold]--snakefile[/bold] or [bold]--config[/bold]") + sys.exit(1) err = 0 if snakefile: files = [i for i in glob.iglob(f"{directory}/workflow/*.smk")] err_dir = f"{directory}/workflow/" - err_file = "snakefiles" + err_file = "There are no snakefiles" if not os.path.exists(f"{directory}/workflow"): err = 1 elif not files: err = 2 + elif config: + files = [f"{directory}/workflow/config.yaml"] + err_dir = f"{directory}/workflow/" + err_file = "There is no [blue]config.yaml[/blue] file" + if not os.path.exists(f"{directory}/workflow"): + err = 1 + elif not os.path.exists(f"{directory}/workflow/config.yaml"): + err = 2 else: files = [i for i in glob.iglob(f"{directory}/logs/snakemake/*.log*")] err_dir = f"{directory}/logs/snakemake/" - err_file = "log files" + err_file = "There are no log files" if not os.path.exists(f"{directory}/logs/snakemake"): err = 1 elif not files: @@ -54,7 +66,7 @@ def view(directory, snakefile): elif err == 2: print_error( "File not found", - f"There are no {err_file} in [blue]{err_dir}[/blue]. Please check that this is the correct folder." + f"{err_file} in [blue]{err_dir}[/blue]. Please check that this is the correct folder." ) sys.exit(1) # sort and pull only the most recent file (based on modification time)