Skip to content

Commit d36ff8c

Browse files
committed
fix: handle empty args list in CommandParser for optional-only commands
fletx doctor and other commands with only optional arguments were rejected by missing_args_message check treating [] as 'no args'. Fix skips the error when no positional args are required (nargs in ?,*).
1 parent 2f23748 commit d36ff8c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

fletx/cli/commands/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ def parse_args(self, args = None, namespace = None):
6565

6666
# Catch missing argument for a better error message
6767
if self.missing_args_message and not (
68-
args or any(not arg.startswith("-") for arg in args)
68+
args or any(not arg.startswith("-") for arg in args or [])
6969
):
70-
self.error(self.missing_args_message)
70+
# Only error if the parser requires at least one positional arg
71+
needs_positional = any(
72+
not action.option_strings
73+
and action.nargs not in ('?', '*')
74+
for action in self._actions
75+
)
76+
if needs_positional:
77+
self.error(self.missing_args_message)
7178
return super().parse_args(args, namespace)
7279

7380
def error(self, message):
@@ -324,7 +331,6 @@ def _build_flet_args(self, args: Namespace) -> list[str]:
324331

325332
def execute(self, args: Namespace) -> None:
326333
argv = [sys.argv[0], self.flet_subcommand, *self._build_flet_args(args)]
327-
env = os.environ.copy()
328334
try:
329335
from flet.cli import main as flet_main
330336
old_argv = sys.argv

0 commit comments

Comments
 (0)