Does carapace provide argument validation for cobra CLIs? #2599
Replies: 2 comments 4 replies
-
Depends on what you want to do. |
Beta Was this translation helpful? Give feedback.
-
Hi @rsteube, my validation scheme already builds upon pflag's Var and VarP, but your PreInvoke looks interetsing. The type of validations that my library provides are these:
Since Var/PVar are type specific, the resultant code is repetitve differing only by type, and since Var/PVar is pre-implemented not using generics, I am restricted either by coding the validators up explicitly, or by using code generators. I have opted for the latter, but I wonder if I could replace these to integrate with carapace somehow. I think Actions will do the trick but not sure. What I would want is to prevent a user from entering an invalid value by being able to validate an option value using a pre-defined validator function. How can this be achieved with an Action? Does the PreInvoke allow for a mechansim where what is typed in by the user is rejected as a result of failing a validation check, eg a numeric field is outside of a predefined range and clears the value so they can correct it, before being accepted? This is the functionality being provided by my validation scheme except it was not based upon completeion and required the user to hit enter, get processed then rejected and the user prompted to start over; clearly this is clumsy compared to the completions approach. I'm very impressed with the work you have completed with this repository as my knowledge on bulding CLIs with advanced features is greatly increased simply by discovering this repo. This does also mean I have to really reconsider the work I have done on my libarary and wonder if its still valid, perhaps I will trash it. Mmmm, just looking at the Group Therapy examples showing multiple concurrent completions taking place (presumebaly in separate go routines, is that correct?). The mind boggles with the potential for what this could be used for! |
Beta Was this translation helpful? Give feedback.
-
I have just discovered this project and am very impressed although I'm still struggling to see how I would integrate with my own cli projects. Initially I thought you just installed caraspace and use it to provide completions for cli programs interactively. But reading a bit more and I discover there is a full blown api too.
This is intriguing to me because I have already written my own cobra assistance library that fills a gap left by cobra in that it doesnt provide a framework for validating arguments after they have been parsed. From what I understand, carapsace works within the pre-parse phase, where as my validation schem works post prase phase so I'm thinking I can use them together, but I am not sure. The carapsace documentation is very good, I havent done a detailed read yet so my current misaprehensions will be resolved after having done so.
But the core of my query is this; does carapsace provide validation after parsing or not? In fact I would be interested in the possibility of integrating my validation scheme directly into caraspace if there would be an opportunity to do so (I'll probably start off with a fork for a feasibility study). I have realised that some parts of what I have implemented (which I did at a very early stage of learning Golang) are either surplace to requirements (as they could be acheived with carapace), or based on a flawed premise (eg my fake enum implementations which are obseleted by completions).
Beta Was this translation helpful? Give feedback.
All reactions