1515
1616import latch_cli .click_utils
1717from latch .ldata ._transfer .progress import Progress as _Progress # noqa: PLC2701
18- from latch .utils import current_workspace
18+ from latch .utils import NoWorkspaceSelectedError , current_workspace
1919from latch_cli .click_utils import EnumChoice
2020from latch_cli .exceptions .handler import CrashHandler
2121from latch_cli .services .cp .autocomplete import complete as cp_complete
@@ -66,6 +66,21 @@ def decorated(*args: P.args, **kwargs: P.kwargs):
6666 return decorated
6767
6868
69+ def requires_workspace (f : Callable [P , T ]) -> Callable [P , T ]:
70+ def decorated (* args : P .args , ** kwargs : P .kwargs ):
71+ try :
72+ current_workspace ()
73+ except NoWorkspaceSelectedError as e :
74+ click .secho (str (e ), fg = "red" )
75+ raise click .exceptions .Exit (1 ) from e
76+
77+ return f (* args , ** kwargs )
78+
79+ decorated .__doc__ = f .__doc__
80+
81+ return decorated
82+
83+
6984@click .group ("latch" , context_settings = {"max_content_width" : 160 })
7085@click .version_option (package_name = "latch" )
7186def main ():
@@ -485,6 +500,7 @@ def generate_metadata(
485500 help = "Size of machine to provision for develop session" ,
486501)
487502@requires_login
503+ @requires_workspace
488504def local_development (
489505 pkg_root : Path ,
490506 yes : bool ,
@@ -533,6 +549,7 @@ def local_development(
533549 help = "Optional container index to inspect (only used for Map Tasks)" ,
534550)
535551@requires_login
552+ @requires_workspace
536553def execute (
537554 execution_id : Optional [str ], egn_id : Optional [str ], container_index : Optional [int ]
538555):
@@ -714,6 +731,7 @@ def image_ls():
714731 ),
715732)
716733@requires_login
734+ @requires_workspace
717735def register (
718736 pkg_root : str ,
719737 disable_auto_version : bool ,
@@ -810,6 +828,7 @@ def register(
810828 help = "The version of the workflow to launch. Defaults to latest." ,
811829)
812830@requires_login
831+ @requires_workspace
813832def launch (params_file : Path , version : Union [str , None ] = None ):
814833 """[DEPRECATED] Launch a workflow using a python parameter map.
815834
@@ -851,6 +870,7 @@ def launch(params_file: Path, version: Union[str, None] = None):
851870 "--version" , default = None , help = "The version of the workflow. Defaults to latest."
852871)
853872@requires_login
873+ @requires_workspace
854874def get_params (wf_name : Union [str , None ], version : Union [str , None ] = None ):
855875 """[DEPRECATED] Generate a python parameter map for a workflow.
856876
@@ -890,6 +910,7 @@ def get_params(wf_name: Union[str, None], version: Union[str, None] = None):
890910 help = "The name of the workflow to list. Will display all versions" ,
891911)
892912@requires_login
913+ @requires_workspace
893914def get_wf (name : Union [str , None ] = None ):
894915 """List workflows."""
895916 crash_handler .message = "Unable to get workflows"
@@ -919,6 +940,7 @@ def get_wf(name: Union[str, None] = None):
919940@main .command ("preview" )
920941@click .argument ("pkg_root" , nargs = 1 , type = click .Path (exists = True , path_type = Path ))
921942@requires_login
943+ @requires_workspace
922944def preview (pkg_root : Path ):
923945 """Creates a preview of your workflow interface."""
924946 crash_handler .message = f"Unable to preview inputs for { pkg_root } "
@@ -931,6 +953,7 @@ def preview(pkg_root: Path):
931953
932954@main .command ("get-executions" )
933955@requires_login
956+ @requires_workspace
934957def get_executions ():
935958 """Spawns an interactive terminal UI that shows all executions in a given workspace"""
936959
@@ -1263,6 +1286,7 @@ def generate_entrypoint(
12631286 "--execution-id" , "-e" , type = str , help = "Optional execution ID to inspect."
12641287)
12651288@requires_login
1289+ @requires_workspace
12661290def attach (execution_id : Optional [str ]):
12671291 """Drops the user into an interactive shell to inspect the workdir of a nextflow execution."""
12681292
@@ -1302,6 +1326,7 @@ def attach(execution_id: Optional[str]):
13021326 help = "Path to the entrypoint nextflow file. Must be relative to the package root." ,
13031327)
13041328@requires_login
1329+ @requires_workspace
13051330def nf_register (
13061331 pkg_root : Path ,
13071332 yes : bool ,
0 commit comments