Improve CLI argument parsing #569

Closed
opened 2022-07-30 18:06:35 +00:00 by pikeas · 2 comments

What I'm trying to do and why

Accidentally ran borgmatic create bad-argument.

Actual behavior (if a bug)

borgmatic: error: argument : invalid choice: 'bad-argument' (choose from 'init', '--init', '-I', 'prune', '--prune', '-p', 'compact', 'create', '--create', '-C', 'check', '--check', '-k', 'extract', '--extract', '-x', 'export-tar', '--export-tar', 'mount', '--mount', '-m', 'umount', '--umount', '-u', 'restore', '--restore', '-r', 'list', '--list', '-l', 'info', '--info', '-i', 'borg')

Expected behavior (if a bug)

Borgmatic should treat bad-argument as a bad argument to borgmatic create instead of as a bad argument to borgmatic.

borgmatic version: 1.6.6

#### What I'm trying to do and why Accidentally ran `borgmatic create bad-argument`. #### Actual behavior (if a bug) ``` borgmatic: error: argument : invalid choice: 'bad-argument' (choose from 'init', '--init', '-I', 'prune', '--prune', '-p', 'compact', 'create', '--create', '-C', 'check', '--check', '-k', 'extract', '--extract', '-x', 'export-tar', '--export-tar', 'mount', '--mount', '-m', 'umount', '--umount', '-u', 'restore', '--restore', '-r', 'list', '--list', '-l', 'info', '--info', '-i', 'borg') ``` #### Expected behavior (if a bug) Borgmatic should treat `bad-argument` as a bad argument to `borgmatic create` instead of as a bad argument to `borgmatic`. **borgmatic version:** 1.6.6
Owner

Thanks for reporting this! However, this behavior is actually by design, in some sense. There are two classes of things given on borgmatic's command-line, flags (e.g., --files) and actions (e.g., create). In your example, since bad-argument doesn't start with a dash, borgmatic is interpreting it as an action since you can specify multiple actions on the command-line at once. So, for instance, borgmatic create list is totally valid. And since bad-argument isn't valid, borgmatic is helpfully listing out other actions for you to choose from instead.

Let me know if that makes sense!

Thanks for reporting this! However, this behavior is actually by design, in some sense. There are two classes of things given on borgmatic's command-line, flags (e.g., `--files`) and actions (e.g., `create`). In your example, since `bad-argument` doesn't start with a dash, borgmatic is interpreting it as an action since you can specify multiple actions on the command-line at once. So, for instance, `borgmatic create list` is totally valid. And since `bad-argument` *isn't* valid, borgmatic is helpfully listing out other actions for you to choose from instead. Let me know if that makes sense!
witten added the
question / support
label 2022-08-01 17:04:03 +00:00
Owner

Closing this for now, but feel free to follow up. We can always reopen it. Thanks!

Closing this for now, but feel free to follow up. We can always reopen it. Thanks!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#569
No description provided.