From 7a766c717e7a6237514d1016d4dd3706766d8e1f Mon Sep 17 00:00:00 2001 From: Gautam Aggarwal Date: Thu, 27 Mar 2025 02:55:16 +0000 Subject: [PATCH] 2nd Draft --- borgmatic/commands/borgmatic.py | 20 ++++++++++---------- borgmatic/config/schema.yaml | 8 +++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index d8c270347..0a6a775c2 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -943,19 +943,18 @@ def exit_with_help_link(): # pragma: no cover sys.exit(1) -def check_and_show_help_on_no_args(): +def check_and_show_help_on_no_args(configs): """ Check if the 'borgmatic' command is run without any arguments. If the configuration option - 'show_help_on_no_args' is set to True, show the help message. Otherwise, trigger the + 'default_actions' is set to False, show the help message. Otherwise, trigger the default backup behavior. """ if len(sys.argv) == 1: # No arguments provided - show_help_on_no_args = any( - config.get('show_help_on_no_args', False) - for config in load_configurations(tuple(collect.collect_config_filenames(None)))[0].values() + default_actions = any( + config.get('default_actions', True) for config in configs.values() ) - if show_help_on_no_args: - print(parse_arguments('--help')) + if not default_actions: + parse_arguments('--help') sys.exit(0) @@ -987,9 +986,6 @@ def main(extra_summary_logs=[]): # pragma: no cover print(borgmatic.commands.completion.fish.fish_completion()) sys.exit(0) - # Use the helper function to check and show help on no arguments - check_and_show_help_on_no_args() - validate = bool('validate' in arguments) config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths)) configs, config_paths, parse_logs = load_configurations( @@ -997,6 +993,10 @@ def main(extra_summary_logs=[]): # pragma: no cover global_arguments.overrides, resolve_env=global_arguments.resolve_env and not validate, ) + + # Use the helper function to check and show help on no arguments, passing the preloaded configs + check_and_show_help_on_no_args(configs) + configuration_parse_errors = ( (max(log.levelno for log in parse_logs) >= logging.CRITICAL) if parse_logs else False ) diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 96bba3b91..65ba9f773 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -2665,9 +2665,11 @@ properties: example: /usr/local/bin/keepassxc-cli description: | Configuration for integration with the KeePassXC password manager. - show_help_on_no_args: + default_actions: type: boolean description: | - If true, running borgmatic without any arguments will display the - help message instead of triggering a backup. Defaults to false. + Whether to apply default actions (e.g., backup) when no arguments + are supplied to the borgmatic command. If set to true, borgmatic + will trigger the default actions. If set to false, borgmatic will + display the help message instead. example: true