From b0e9f79f2a0dfd80502fbebaee76a455906d59e2 Mon Sep 17 00:00:00 2001 From: Adal Chiriliuc Date: Thu, 25 Apr 2024 19:36:29 +0300 Subject: [PATCH] file hide subcommand --- b2/_internal/console_tool.py | 13 +++++++++++- test/integration/test_b2_command_line.py | 2 +- test/unit/_cli/test_autocomplete_cache.py | 4 ++-- test/unit/test_console_tool.py | 26 +++++++++++------------ 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/b2/_internal/console_tool.py b/b2/_internal/console_tool.py index 985263a9..ab2a6a69 100644 --- a/b2/_internal/console_tool.py +++ b/b2/_internal/console_tool.py @@ -2113,7 +2113,7 @@ def _run(self, args): return 0 -class HideFile(Command): +class FileHideBase(Command): """ Uploads a new, hidden, version of the given file. @@ -4925,6 +4925,12 @@ class FileCopyById(FileCopyByIdBase): COMMAND_NAME = 'CopyById' +@File.subcommands_registry.register +class FileHide(FileHideBase): + __doc__ = FileHideBase.__doc__ + COMMAND_NAME = 'hide' + + class FileInfo2(CmdReplacedByMixin, B2URIFileArgMixin, FileInfoBase): __doc__ = FileInfoBase.__doc__ replaced_by_cmd = (File, FileInfo) @@ -4982,6 +4988,11 @@ class CopyFileById(CmdReplacedByMixin, FileCopyByIdBase): replaced_by_cmd = (File, FileCopyById) +class HideFile(CmdReplacedByMixin, FileHideBase): + __doc__ = FileHideBase.__doc__ + replaced_by_cmd = (File, FileHide) + + class ConsoleTool: """ Implements the commands available in the B2 command-line tool diff --git a/test/integration/test_b2_command_line.py b/test/integration/test_b2_command_line.py index 465857f8..5c0824f1 100755 --- a/test/integration/test_b2_command_line.py +++ b/test/integration/test_b2_command_line.py @@ -350,7 +350,7 @@ def test_basic(b2_tool, bucket_name, sample_file, tmp_path, b2_uri_args): ['file', 'download', '--quiet', f'b2://{bucket_name}/b/1', tmp_path / 'a'] ) - b2_tool.should_succeed(['hide-file', bucket_name, 'c']) + b2_tool.should_succeed(['file', 'hide', bucket_name, 'c']) list_of_files = b2_tool.should_succeed_json( ['ls', '--json', '--recursive', *b2_uri_args(bucket_name)] diff --git a/test/unit/_cli/test_autocomplete_cache.py b/test/unit/_cli/test_autocomplete_cache.py index 41e0c736..383e224b 100644 --- a/test/unit/_cli/test_autocomplete_cache.py +++ b/test/unit/_cli/test_autocomplete_cache.py @@ -176,7 +176,7 @@ def test_complete_with_escaped_control_characters( store=autocomplete_cache.HomeCachePickleStore(tmp_path), ) - with autocomplete_runner(f'b2 hide-file {bucket} '): + with autocomplete_runner(f'b2 file hide {bucket} '): exit, argcomplete_output = argcomplete_result() assert exit == 0 assert escaped_cc_file_name in argcomplete_output @@ -200,7 +200,7 @@ def test_complete_with_file_suggestions( tracker=autocomplete_cache.VersionTracker(), store=autocomplete_cache.HomeCachePickleStore(tmp_path), ) - with autocomplete_runner(f'b2 hide-file {bucket} '): + with autocomplete_runner(f'b2 file hide {bucket} '): exit, argcomplete_output = argcomplete_result() assert exit == 0 assert file_name in argcomplete_output diff --git a/test/unit/test_console_tool.py b/test/unit/test_console_tool.py index 18b65109..73462221 100644 --- a/test/unit/test_console_tool.py +++ b/test/unit/test_console_tool.py @@ -1081,7 +1081,7 @@ def test_files(self): } self._run_command( - ['hide-file', 'my-bucket', 'file1.txt'], + ['file', 'hide', 'my-bucket', 'file1.txt'], expected_json_in_stdout=expected_json, ) @@ -1269,7 +1269,7 @@ def test_files_encrypted(self): } self._run_command( - ['hide-file', 'my-bucket', 'file1.txt'], + ['file', 'hide', 'my-bucket', 'file1.txt'], expected_json_in_stdout=expected_json, ) @@ -1982,10 +1982,10 @@ def test_get_bucket_with_hidden(self): # something has failed if the output of 'bucket get' does not match the canon. stdout, stderr = self._get_stdouterr() console_tool = self.console_tool_class(stdout, stderr) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', 'hidden1']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', 'hidden2']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', 'hidden3']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', 'hidden4']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden1']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden2']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden3']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', 'hidden4']) # Now check the output of `bucket get` against the canon. expected_json = { @@ -2043,13 +2043,13 @@ def test_get_bucket_complex(self): # something has failed if the output of 'bucket get' does not match the canon. stdout, stderr = self._get_stdouterr() console_tool = self.console_tool_class(stdout, stderr) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/hidden1']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/hidden1']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/hidden2']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/2/hidden3']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/2/hidden3']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/2/hidden3']) - console_tool.run_command(['b2', 'hide-file', 'my-bucket', '1/2/hidden3']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/hidden1']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/hidden1']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/hidden2']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/2/hidden3']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/2/hidden3']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/2/hidden3']) + console_tool.run_command(['b2', 'file', 'hide', 'my-bucket', '1/2/hidden3']) # Now check the output of `bucket get` against the canon. expected_json = {