Borgmatic without arguments/parameters should show usage help instead of starting a backup #262
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I often type
borgmaticand hit enter in order to get help on it's subcommands and it always confuses me that it starts a backup instead.Most applications show their usage help without doing anything when called without arguments/parameters so I propose borgmatic to do the same.
I agree that borgmatic is a little different than most command-line applications in this respect, but I don't think we could make a change like this without breaking a number of existing borgmatic uses (whether manual or automated) that rely on just running
borgmaticdirectly without any arguments. And I think that's kind of the promise of borgmatic in some ways: Once you get your configuration file set up correctly, you don't have to pass any (or very many) arguments to borgmatic on the command-line.I guess a config option disabled by default would be good for that.
Yup, that could certainly work!
how should I proceed with this issue here and what needs to be implemented??
The idea is that there could be a new boolean configuration option that, when enabled, means that running
borgmaticwithout any actions displays borgmatic help instead of running the default actions. But by default (without that configuration option present or with it set to false), borgmatic would continue to run default actions when none are specified on the command-line.So you could proceed directly to a PR given that this is hopefully not too large. Or if you prefer you can write up your implementation plan for review. Thanks!
Here is my implementation plan for this issue-
def check_and_show_help_on_no_args():
"""
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 and exit. Otherwise, trigger the default backup behavior.
"""
i cant figure out how should we pass the value of show_help_on_no_args.Should we have a separate config file or it needs to be in some file in existing file structure?Also pls guide if I am moving in correct direction from above code
Here are my thoughts:
The "ideal" place to do the kind of logic you're proposing would be in
borgmatic/commands/arguments.py:parse_argument_for_actions()and specifically somewhere around this code:... because that's where the decision to run the default actions is made, and so you could in theory make a different decision if your proposed configuration option is set.
The problem: This code runs way before any configuration files are actually loaded, because we're not even done with parsing command-line flags at this point. And those flags can (among other things) specify which configuration files to load! (I don't think it makes sense to have a separate purpose-specific configuration file for this feature.)
So that leaves a less-than-ideal location to call your code: After configuration files have already been loaded and parsed. For instance, somewhere in
borgmatic/commands/borgmatic.py:main()afterload_configurations(). There, I think an approach like what you outlined could work, but it'd probably have to iterate the configs to see if any have the proposed new option set. If so, your logic could trigger. It might be enough though to checksys.argvlength there and not do the== 'borgmatic'check...?This is implemented in main by @gautamaggarwal2810 and will be part of the next release!
Released in borgmatic 2.0.0! Docs here: https://torsion.org/borgmatic/docs/how-to/set-up-backups/#disabling-default-actions