Replies: 3 comments 5 replies
-
@ronnyek could you explain a bit what your use case is and what you are missing from the existing functionality? |
Beta Was this translation helpful? Give feedback.
-
Imagine I have a logs command, that has explicit settings like so: public class LogsCommandSettings: CommandSettings
{
[CommandArgument(0, "[container]")]
public required string Container { get; set; }
[CommandOption("-f|--follow")]
public bool? Follow { get; set; }
} What I was hoping to do was keep the definition of LogsCommandSettings exactly as it appears (such that by the time the command executes, all the required properties are present. Where my desires potentially miss the functionality present (that I've seen) is that if you specify the command but omit say the Container argument, I'd like to be able to hook into things right there... like if logs is there but the required argument was not specified, I'd like to be able to provide a My hope is that by having that hook, I could do something like prompt someone to use previous runs parameters or maybe in some cases go get a list of containers. I realize I could probably do this by not making this required (and in the case of primitives, make then nullable), but then it seems like I'd have to provide a lot more checking and validation to guarantee by the time we are actually trying to run the command, we have everything actually required to execute. |
Beta Was this translation helpful? Give feedback.
-
So I've had a bit of time to evaluate / tinker with some ideas, and I think the biggest problem is that validation of a commands settings, at least in practice thus far (examples and such) tend to resort to throwing exceptions, vs returning some sort of validation result. I tested creating a new method on the Another option that seems like it could be may useful seems like the idea of a resolver. I know there is a resolver type, that I believe is responsible for parsing command arguments and binding, if there was a way to say we didnt get this argument at the time of binding, and could then use a registered fallback resolver (perhaps I could do the equivalent of what I'm trying to do with interceptors). I think in both cases, it would depend on validate at the commandsettings validate method to work more like command validate method works. Curious if anyone has some input on that experimentation. |
Beta Was this translation helpful? Give feedback.
-
First of all, let me state that I'm unaware of whether this is already achievable... it may not be a feature that needs building.
Is your feature request related to a problem? Please describe.
Well what I'd like to do is have a command have parameters as usual, and still specify required parameters etc... but in the event the user didn't provide them, prompt for them, or even just offer to allow them to use the most recent parameters for that command (I can implement the persistence of that...)
I guess the question is is there a way to intercept a command call with missing parameters so we can potentially fulfil them via other means before executing?
I'd prefer not to just make everything optional, but I suppose if that's what I have to do, that's what I have to do.
With my limited experience with the library I was hoping for something like this...
No changes to command and parameters
If spectre.console decides parameters are missing and that it should display help prompt, allow a hook that would let me gather supply those parameters before attempting to run somehow.
If there is already a way to achieve this, awesome... if not... I feel like this could be extremely handy in at least my use cases.
Thanks for the consideration / feedback.
Beta Was this translation helpful? Give feedback.
All reactions