@@ -235,6 +235,22 @@ def _split_to_groups(args: list[str]) -> tuple[list[list[str]], list[str]]:
235235 groups .append (args_group )
236236 return groups , used_cmds
237237
238+ @staticmethod
239+ def repeat_read_commands (
240+ used_cmds : list [str ], groups : list [list [str ]]
241+ ) -> list [list [str ]]:
242+ if (
243+ sum (cmd in SUPPORTED_BURN_COMMANDS for cmd in used_cmds ) > 0
244+ and sum (cmd in SUPPORTED_READ_COMMANDS for cmd in used_cmds ) > 0
245+ ):
246+ # append all read commands at the end of group
247+ read_commands = []
248+ for group in groups :
249+ if group [0 ] in SUPPORTED_READ_COMMANDS :
250+ read_commands .append (group )
251+ groups .extend (read_commands )
252+ return groups
253+
238254 def parse_args (self , ctx : click .Context , args : list [str ]):
239255 ctx .ensure_object (dict )
240256 ctx .obj ["is_help" ] = any (help_arg in args for help_arg in ctx .help_option_names )
@@ -247,12 +263,15 @@ def parse_args(self, ctx: click.Context, args: list[str]):
247263 # override the default behavior of EsptoolGroup, because we don't need
248264 # support for parameters with nargs=-1
249265 args = self ._replace_deprecated_args (args )
250- _ , used_cmds = self ._split_to_groups (args )
266+ cmd_groups , used_cmds = self ._split_to_groups (args )
251267
252268 if len (used_cmds ) == 0 :
253269 self .get_help (ctx )
254270 ctx .exit ()
255271
272+ cmd_groups = self .repeat_read_commands (used_cmds , cmd_groups )
273+ args = [arg for group in cmd_groups for arg in group ]
274+
256275 ctx .obj ["used_cmds" ] = used_cmds
257276 ctx .obj ["args" ] = args
258277 return super (click .RichGroup , self ).parse_args (ctx , args )
0 commit comments