Conversation
|
Looks good, but I think there's an edge case I stumbled on my own previously When arguments are empty, When no groups can be made, nothing is run. I "solved" that by making an empty group via |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #756 +/- ##
=======================================
Coverage 89.62% 89.62%
=======================================
Files 71 71
Lines 8040 8040
Branches 1809 1809
=======================================
Hits 7206 7206
Misses 474 474
Partials 360 360
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
fixed! I'll merge this soon unless you have any objections/feedback! |
|
No objections, only but a feedback that it comes down to preference to either have the auxiliary Yours solution doesn't depend on |
|
Ah, I just noticed something, this ignores/allows unknown arguments before a group (in mine too):
Should we force a group to start at the first index or raise exceptions if not known command? |
|
Solution: Simply start with an empty group! 🙂 def split_commands(app, tokens):
groups = [[]]
for token in tokens:
if token in app:
groups.append([])
groups[-1].append(token)
return groups |
|
Sorry minor spam, looks good inlined too and is much simpler @app.meta.default
def main(*tokens: Annotated[str, Parameter(show=False, allow_leading_hyphen=True)]):
group = []
for token in tokens:
if token in app:
app(group)
group.clear()
group.append(token)
app(group)The last call handles both the last group that doesn't match a new command and empty runs |
Addresses #754.
@Tremeschin what do you think about this?