55from multiprocessing import freeze_support
66from typing import TYPE_CHECKING , Optional
77
8- from datachain .cli .commands .storages import cp_storage
98from datachain .cli .utils import get_logging_level
109
1110from .commands import (
2625logger = logging .getLogger ("datachain" )
2726
2827if TYPE_CHECKING :
28+ from argparse import Namespace
29+
2930 from datachain .catalog import Catalog
3031
3132
@@ -82,7 +83,6 @@ def main(argv: Optional[list[str]] = None) -> int:
8283
8384def handle_command (args , catalog , client_config ) -> int :
8485 """Handle the different CLI commands."""
85- from datachain .cli .commands .storages import mv_storage , rm_storage
8686 from datachain .studio import process_auth_cli_args , process_jobs_args
8787
8888 command_handlers = {
@@ -101,8 +101,8 @@ def handle_command(args, catalog, client_config) -> int:
101101 "gc" : lambda : garbage_collect (catalog ),
102102 "auth" : lambda : process_auth_cli_args (args ),
103103 "job" : lambda : process_jobs_args (args ),
104- "mv" : lambda : mv_storage (args ),
105- "rm" : lambda : rm_storage (args ),
104+ "mv" : lambda : handle_mv_command (args , catalog ),
105+ "rm" : lambda : handle_rm_command (args , catalog ),
106106 }
107107
108108 handler = command_handlers .get (args .command )
@@ -115,23 +115,36 @@ def handle_command(args, catalog, client_config) -> int:
115115 return 1
116116
117117
118- def handle_cp_command (args , catalog : "Catalog" ):
118+ def _get_storage_implementation (args : "Namespace" , catalog : "Catalog" ):
119+ from datachain .cli .commands .storage import (
120+ LocalStorageImplementation ,
121+ StudioStorageImplementation ,
122+ )
119123 from datachain .config import Config
120124
121125 config = Config ().read ().get ("studio" , {})
122126 token = config .get ("token" )
123- local = True if not token else args .local
124- if local :
125- return catalog .cp (
126- [args .source_path ],
127- args .destination_path ,
128- force = bool (args .force ),
129- update = bool (args .update ),
130- recursive = bool (args .recursive ),
131- no_glob = args .no_glob ,
132- )
127+ studio = False if not token else args .studio_cloud_auth
128+ return (
129+ StudioStorageImplementation (args , catalog )
130+ if studio
131+ else LocalStorageImplementation (args , catalog )
132+ )
133+
134+
135+ def handle_cp_command (args , catalog ):
136+ storage_implementation = _get_storage_implementation (args , catalog )
137+ return storage_implementation .cp ()
138+
139+
140+ def handle_mv_command (args , catalog ):
141+ storage_implementation = _get_storage_implementation (args , catalog )
142+ return storage_implementation .mv ()
143+
133144
134- return cp_storage (args )
145+ def handle_rm_command (args , catalog ):
146+ storage_implementation = _get_storage_implementation (args , catalog )
147+ return storage_implementation .rm ()
135148
136149
137150def handle_clone_command (args , catalog ):
0 commit comments