@@ -235,6 +235,22 @@ def _split_to_groups(args: list[str]) -> tuple[list[list[str]], list[str]]:
235
235
groups .append (args_group )
236
236
return groups , used_cmds
237
237
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
+
238
254
def parse_args (self , ctx : click .Context , args : list [str ]):
239
255
ctx .ensure_object (dict )
240
256
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]):
247
263
# override the default behavior of EsptoolGroup, because we don't need
248
264
# support for parameters with nargs=-1
249
265
args = self ._replace_deprecated_args (args )
250
- _ , used_cmds = self ._split_to_groups (args )
266
+ cmd_groups , used_cmds = self ._split_to_groups (args )
251
267
252
268
if len (used_cmds ) == 0 :
253
269
self .get_help (ctx )
254
270
ctx .exit ()
255
271
272
+ cmd_groups = self .repeat_read_commands (used_cmds , cmd_groups )
273
+ args = [arg for group in cmd_groups for arg in group ]
274
+
256
275
ctx .obj ["used_cmds" ] = used_cmds
257
276
ctx .obj ["args" ] = args
258
277
return super (click .RichGroup , self ).parse_args (ctx , args )
0 commit comments