4444LOCAL_ONLY_COMMANDS = ("format" ,)
4545
4646
47+ class _SQLMeshGroup (click .Group ):
48+ def parse_args (self , ctx : click .Context , args : t .List [str ]) -> t .List [str ]:
49+ rest = super ().parse_args (ctx , args )
50+ # Preserve the subcommand arguments because Click consumes them before invoking the group callback.
51+ protected_args = getattr (ctx , "_protected_args" , None )
52+ if protected_args is None :
53+ protected_args = ctx .protected_args
54+ ctx .meta ["subcommand_args" ] = tuple (protected_args ) + tuple (ctx .args )
55+ return rest
56+
57+
4758def _sqlmesh_version () -> str :
4859 try :
4960 from sqlmesh import __version__
@@ -53,7 +64,7 @@ def _sqlmesh_version() -> str:
5364 return "0.0.0"
5465
5566
56- @click .group (no_args_is_help = True )
67+ @click .group (cls = _SQLMeshGroup , no_args_is_help = True )
5768@click .version_option (version = _sqlmesh_version (), message = "%(version)s" )
5869@opt .paths
5970@opt .config
@@ -118,7 +129,8 @@ def cli(
118129 load = True
119130 # Local-only gating must hold for any number of --paths, so it stays outside the block below.
120131 load_state = ctx .invoked_subcommand not in LOCAL_ONLY_COMMANDS
121- if ctx .invoked_subcommand == "lint" and "--local" in sys .argv :
132+ # The parent callback constructs Context before Click invokes `lint`, so inspect its parsed args here.
133+ if ctx .invoked_subcommand == "lint" and "--local" in ctx .meta ["subcommand_args" ]:
122134 load_state = False
123135
124136 if len (paths ) == 1 :
0 commit comments