consider: forbid ordered arguments on commands with subcommands #9
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This has not already been implemented due to "maybe it would be useful in a weird scenario", but the more I think about it, the more I think it is a bad idea that permits the creation of confusing command lines. One of the goals of NOCLIP is to, while providing a lot of flexibility, encourage the creation of consistent and coherent command line interfaces across applications.
Optional ordered arguments can especially violate the principle of least astonishment here. In short, I can't think of any use cases that actually benefit from having ordered arguments preceding a subcommand.
From an implementation perspective, since subcommands are frequently added at runtime as type-erased interfaces to other type-erased interfaces, achieving this logic at compile time will probably be a bit messy. I don't see an immediately obvious implementation path at the moment. This may have to be a blatant runtime check, like the global option check in #1 would have to be, and that might be an argument against implementing it.
One possible option for making this compile-time behavior would be to remove
addSubcommand
from the parser interface and add a method to the generic parser instance to easily get a heap-allocated copy for longevity. This way all subcommands would have to be added to the generic parser before it is turned into an interface. Since the generic parser holds an arena allocator, it can trivially allocate itself.This sounds like it would give the ability to add additional compile-time checks without having a big negative impact on API ergonomics, which I think would be a net win, even though it would make things slightly clunkier.
This would make it harder to dynamically add subcommands outside of the scope in which the root parser is defined, but that's not really a planned use case, and goes somewhat against the declarative, localized style of the API anyway.