config bootstrap CLI parsing issues #712

Closed
opened 2023-06-16 16:54:33 +00:00 by witten · 4 comments
Owner

What I'm trying to do and why

As part of developing another feature (#529), I found a few edge cases where the new config bootstrap action (#697) doesn't work quite as intended on the command-line.

First issue: Steps to reproduce

$ borgmatic -v 1 config bootstrap --repository 1.2.borg

First issue: Actual behavior

usage: borgmatic config [-h] {bootstrap} ...
borgmatic config: error: argument {bootstrap}: invalid choice: '1' (choose from 'bootstrap')
Error parsing arguments: /usr/bin/borgmatic -v 1 config bootstrap --repository 1.2.borg

First issue: Expected behavior

Successful bootstrap with verbosity level 1.

Second issue: Steps to reproduce

$ borgmatic -v 1 bootstrap --repository 1.2.borg

Second issue: Actual behavior

Bootstrapping config paths: /root/tmp/test.yaml

summary:
Bootstrap successful

Second issue: Expected behavior

Error about unknown bootstrap action or similar, as the parent config action is missing.

Other notes / implementation ideas

Some of this might be a side effect of the bootstrap argument parser "living" at the top level alongside the other parsers.

Environment

borgmatic version: main (these issues do not occur in any released versions)

borgmatic installation method: pip editable

Borg version: 1.2.4

Python version: 3.10.10

Database version (if applicable): n/a

operating system and version: Manjaro stable

#### What I'm trying to do and why As part of developing another feature (#529), I found a few edge cases where the new `config bootstrap` action (#697) doesn't work quite as intended on the command-line. #### First issue: Steps to reproduce ``` $ borgmatic -v 1 config bootstrap --repository 1.2.borg ``` #### First issue: Actual behavior ``` usage: borgmatic config [-h] {bootstrap} ... borgmatic config: error: argument {bootstrap}: invalid choice: '1' (choose from 'bootstrap') Error parsing arguments: /usr/bin/borgmatic -v 1 config bootstrap --repository 1.2.borg ``` #### First issue: Expected behavior Successful bootstrap with verbosity level 1. #### Second issue: Steps to reproduce ``` $ borgmatic -v 1 bootstrap --repository 1.2.borg ``` #### Second issue: Actual behavior ``` Bootstrapping config paths: /root/tmp/test.yaml summary: Bootstrap successful ``` #### Second issue: Expected behavior Error about unknown `bootstrap` action or similar, as the parent `config` action is missing. #### Other notes / implementation ideas Some of this might be a side effect of the `bootstrap` argument parser "living" at the top level alongside the other parsers. #### Environment **borgmatic version:** main (these issues do not occur in any released versions) **borgmatic installation method:** pip editable **Borg version:** 1.2.4 **Python version:** 3.10.10 **Database version (if applicable):** n/a **operating system and version:** Manjaro stable
witten added the
bug
label 2023-06-16 16:54:40 +00:00
Author
Owner

I have a fix in hand. I may have, uh, majorly refactored all of argument parsing though as part of this. Currently working on tests....

I have a fix in hand. I may have, uh, majorly refactored all of argument parsing though as part of this. Currently working on tests....
Author
Owner

Done and pushed. High-level, even before #697, argument parsing was kind of a complexity farm, having gotten that way through gradual accretion. So it wasn't a great foundation upon which to build the #697 config bootstrap feature. As part of fixing this ticket, I did a refactor of argument parsing both to support the bootstrap use cases and all the other random argument parsing use cases that code needed to support. I think the end result is still quite complex and more than a little brittle, but some of the incidental complexity has been stripped away.

Summary of changes:

  • Get rid of the multiple loops over arguments and repeated parse_known_args() calls. There's a single pass now.
  • Instead of merging sub-parsers and sub-sub-parsers (which caused some of the issues in this ticket), now sub-actions are parsed as part of parsing actions.
  • I standardized the terminology in the arguments parsing, so it's almost all now in terms of "actions" and "sub-actions".
  • Much of the argument parsing has been broken out to individually tested utility functions where possible.
  • More integration tests to cover many of the sub-action use cases and edge cases, including ones from this ticket.
  • Probably a bunch of stuff I'm forgetting.

I want to emphasize that this is largely me cleaning up long-standing tech debt in this area of code while still trying to incorporate and support your changes from #697.

Done and pushed. High-level, even before #697, argument parsing was kind of a complexity farm, having gotten that way through gradual accretion. So it wasn't a great foundation upon which to build the #697 `config bootstrap` feature. As part of fixing this ticket, I did a refactor of argument parsing both to support the `bootstrap` use cases and all the other random argument parsing use cases that code needed to support. I think the end result is still quite complex and more than a little brittle, but _some_ of the incidental complexity has been stripped away. Summary of changes: * Get rid of the multiple loops over arguments and repeated `parse_known_args()` calls. There's a single pass now. * Instead of merging sub-parsers and sub-sub-parsers (which caused some of the issues in this ticket), now sub-actions are parsed as part of parsing actions. * I standardized the terminology in the arguments parsing, so it's almost all now in terms of "actions" and "sub-actions". * Much of the argument parsing has been broken out to individually tested utility functions where possible. * More integration tests to cover many of the sub-action use cases and edge cases, including ones from this ticket. * Probably a bunch of stuff I'm forgetting. I want to emphasize that this is largely me cleaning up long-standing tech debt in this area of code while still trying to incorporate and support your changes from #697.
witten reopened this issue 2023-06-21 17:20:03 +00:00
Author
Owner

Found another couple...

3. Steps to reproduce

$ borgmatic config bootstrap --repository 1.2.borg -v 1

3. Actual behavior

usage: borgmatic config [-h] {bootstrap} ...
borgmatic config: error: argument {bootstrap}: invalid choice: '1' (choose from 'bootstrap')
Error parsing arguments: /usr/bin/borgmatic config bootstrap --repository 1.2.borg -v 1

3. Expected behavior

Successful bootstrap with verbosity level 1.

...

4. Steps to reproduce

$ borgmatic -c test.yaml config bootstrap --repository 1.2.borg

4. Actual behavior

summary:
/root/tmp/config: Error parsing configuration file
[Errno 2] No such file or directory: '/root/tmp/config'
Bootstrap successful

4. Expected behavior

The config action is not treated as a second configuration file, the actual configuration file is ignored, and the bootstrap proceeds as per normal.

Found another couple... #### 3. Steps to reproduce ``` $ borgmatic config bootstrap --repository 1.2.borg -v 1 ``` #### 3. Actual behavior ``` usage: borgmatic config [-h] {bootstrap} ... borgmatic config: error: argument {bootstrap}: invalid choice: '1' (choose from 'bootstrap') Error parsing arguments: /usr/bin/borgmatic config bootstrap --repository 1.2.borg -v 1 ``` #### 3. Expected behavior Successful bootstrap with verbosity level 1. ... #### 4. Steps to reproduce ``` $ borgmatic -c test.yaml config bootstrap --repository 1.2.borg ``` #### 4. Actual behavior ``` summary: /root/tmp/config: Error parsing configuration file [Errno 2] No such file or directory: '/root/tmp/config' Bootstrap successful ``` #### 4. Expected behavior The `config` action is not treated as a second configuration file, the actual configuration file is ignored, and the bootstrap proceeds as per normal.
Author
Owner

Just released in borgmatic 1.7.15.

Just released in borgmatic 1.7.15.
Sign in to join this conversation.
No Milestone
No Assignees
1 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#712
No description provided.