Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added file subcommands #284

Merged
merged 22 commits into from
Apr 30, 2024
Merged

Added file subcommands #284

merged 22 commits into from
Apr 30, 2024

Conversation

adal-chiriliuc-reef
Copy link

@adal-chiriliuc-reef adal-chiriliuc-reef commented Apr 25, 2024

Added file subcommands:

b2 file info
b2 file url
b2 file cat
b2 file upload
b2 file download
b2 file copy-by-id
b2 file hide
b2 file update

Copy link

@mjurbanski-reef mjurbanski-reef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great

Comment on lines 4950 to 4957
{NAME} file info b2://yourBucket/file.txt
{NAME} file url b2://yourBucket/file.txt
{NAME} file cat b2://yourBucket/file.txt
{NAME} file upload yourBucket localFile.txt file.txt
{NAME} file download b2://yourBucket/file.txt localFile.txt
{NAME} file copy-by-id sourceFileId yourBucket file.txt
{NAME} file hide yourBucket file.txt
{NAME} file update --legal-hold off b2://yourBucket/file.txt

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order seems pretty random
maybe just sort these lines?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to somewhat group them, first gets, then upload/download, then updates. Will sort

Comment on lines 4995 to 4996
# TODO we can't use 'copy-by-id', gets transformed to 'copy--by--id'
COMMAND_NAME = 'CopyById'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you fix these? Seems like simple change, for example:

diff --git a/b2/_internal/console_tool.py b/b2/_internal/console_tool.py
index ade898c..269ecf8 100644
--- a/b2/_internal/console_tool.py
+++ b/b2/_internal/console_tool.py
@@ -901,7 +901,9 @@ class Command(Described, metaclass=ABCMeta):
 
     @classmethod
     def name_and_alias(cls):
-        name = mixed_case_to_hyphens(cls.COMMAND_NAME or cls.__name__)
+        name = cls.COMMAND_NAME or cls.__name__
+        if '-' not in name:
+            name = mixed_case_to_hyphens()
         alias = None
         if '-' in name:
             alias = name.replace('-', '_')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is exactly what I was looking at.

There is another related issue, where both versions (with _ and with -) are listed, I think we should not show the _ version:

b2 bucket [-h] {..., notification-rule,notification_rule}

Copy link

@mjurbanski-reef mjurbanski-reef Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should be fixable somewhere around

for choice in self._unique_choice_values(action):

perhaps in _unique_choice_values itself

let me know if you want me to take care of it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'll fix it, I just wasn't sure we want to

@adal-chiriliuc-reef
Copy link
Author

adal-chiriliuc-reef commented Apr 26, 2024

I've added a hackish workaround to hide the aliased subcommands
b2 bucket [-h] {..., notification-rule,notification_rule}

Not sure if it's acceptable or not.

I just realized that since we support a ton of versions, from 3.7 to 3.12, there is a probability that argparse internals vary between them.

@adal-chiriliuc-reef adal-chiriliuc-reef force-pushed the subcommands-file branch 5 times, most recently from fdbcd5c to 01505b6 Compare April 29, 2024 19:47
@mjurbanski-reef mjurbanski-reef merged commit c554692 into master Apr 30, 2024
30 checks passed
@mjurbanski-reef mjurbanski-reef deleted the subcommands-file branch April 30, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants