Skip to content

Commit

Permalink
Merge pull request Backblaze#1025 from reef-technologies/subcommands-…
Browse files Browse the repository at this point in the history
…file

Added file subcommands
  • Loading branch information
mjurbanski-reef authored Apr 30, 2024
2 parents e5cafd6 + e294c7a commit c554692
Show file tree
Hide file tree
Showing 23 changed files with 809 additions and 282 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ cat source_file.txt | docker run -i --rm -v b2:/root backblazeit/b2:latest b2v3
or by mounting local files in the docker container:

```bash
docker run --rm -v b2:/root -v /home/user/path/to/data:/data backblazeit/b2:latest b2v3 upload-file bucket_name /data/source_file.txt target_file_name
docker run --rm -v b2:/root -v /home/user/path/to/data:/data backblazeit/b2:latest b2v3 file upload bucket_name /data/source_file.txt target_file_name
```

## ApiVer CLI versions (`b2` vs `b2v3`, `b2v4`, etc.)
Expand Down
3 changes: 2 additions & 1 deletion b2/_internal/_b2v4/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
B2.register_subcommand(Cat)
B2.register_subcommand(GetAccountInfo)
B2.register_subcommand(GetBucket)
B2.register_subcommand(FileInfo)
B2.register_subcommand(FileInfo2)
B2.register_subcommand(GetFileInfo)
B2.register_subcommand(GetDownloadAuth)
B2.register_subcommand(GetDownloadUrlWithAuth)
Expand Down Expand Up @@ -60,3 +60,4 @@
B2.register_subcommand(Replication)
B2.register_subcommand(Account)
B2.register_subcommand(BucketCmd)
B2.register_subcommand(File)
25 changes: 25 additions & 0 deletions b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ def print_help(self, *args, show_all: bool = False, **kwargs):
):
super().print_help(*args, **kwargs)

def format_usage(self):
# TODO We don't want to list underscore aliases subcommands in the usage.
# Unfortunately the only way found was to temporarily remove the aliases,
# print the usage and then restore the aliases since the formatting is deep
# inside the Python argparse module.
# We restore the original dictionary which we don't modify, just in case
# someone else has taken a reference to it.
subparsers_action = None
original_choices = None
if self._subparsers is not None:
for action in self._subparsers._actions:
if isinstance(action, argparse._SubParsersAction):
subparsers_action = action
original_choices = action.choices
action.choices = {
key: choice
for key, choice in action.choices.items() if "_" not in key
}
# only one subparser supported
break
usage = super().format_usage()
if subparsers_action is not None:
subparsers_action.choices = original_choices
return usage


SUPPORT_CAMEL_CASE_ARGUMENTS = False

Expand Down
1 change: 1 addition & 0 deletions b2/_internal/b2v3/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ class Ls(B2URIBucketNFolderNameArgMixin, BaseLs):
B2.register_subcommand(Replication)
B2.register_subcommand(Account)
B2.register_subcommand(BucketCmd)
B2.register_subcommand(File)
1 change: 1 addition & 0 deletions b2/_internal/b2v3/rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ class Rm(B2URIBucketNFolderNameArgMixin, BaseRm):
- **listFiles**
- **deleteFiles**
- **bypassGovernance** (if --bypass-governance is used)
"""
Loading

0 comments on commit c554692

Please sign in to comment.