Comments (7)
@frodgesh I'm not sure if I understand correctly but I'll try to answer you based on the question I can imagine that you're asking for;
Validator
is just a function of form: func(ans interface{}) error
, the ans
is the answer given from the user by terminal and if the returned error is not nil then the answer is invalid and it asks again.
You can use it anywhere you like, remember they're just functions, the AskOne
is just a helper which you can pass a nil
on its third input argument if you don't want them.
You can use Validators
all over the place, look the README.md example, it has a Validation:
field on Question
struct: https://github.com/AlecAivazis/survey/blob/master/survey.go#L28 but this doesn't limit you to use those functions in other places inside your project as well!
from survey.
@frodgesh thanks for submitting another issue. I'm slightly confused what exactly you're asking - do you mind providing a code block for the API you would like to see?
from survey.
@AlecAivazis, sorry about my explanation. I'm just asking, if it's possible to use validation above the AskOne
.
from survey.
@kataras, I don't even know, how did I pass away the third argument, sorry for my clumsiness. And what about using Transform
field in the helper's function?
from survey.
Thanks for helping out @kataras, I hope this clears things up for you @frodgesh.
I was just thinking about whether or not we wanted to include a Transformer
as an arg to AskOne
. Since Transformers
are just normal functions, you can perform the transformation on the variable after calling AskOne
.
FWIW, i opted to not add it as an arg to AskOne
to avoid breaking the top-level API.
from survey.
No problem, yes I didn't add those on AskOne
for the same reason, although I think that AskOne
should be avoided because we can't add many input arguments as struct fields on the Ask(...,Question)
from survey.
@kataras, you said the exact reason, why did I open the issue.
from survey.
Related Issues (20)
- jungaretti:jungaretti/add-proto-guide HOT 1
- Please update golang.org/x/text v0.3.3 to latest version due to security issues
- Support for `fmt.Stringer` interface to display structs in `Select`/`MultiSelect`
- how can I disable text color on Select description text? HOT 1
- multiple selection,get the key from the console by default
- Question duplicates on windows cmd HOT 7
- Arrow keys providing garbage input under Windows HOT 1
- Raid1
- template: prompt:4:19: executing "option" at <.CurrentOpt.Value>: can't evaluate field Value in type bgUEpkv_iHV.IA6nAoo
- Ability to 'clear' terminal
- survey.Multiline The display of the input at the bottom of the terminal is covered
- Why survery.v1 go.mod need import survery v2
- How to disable Logic of Cleanup in Prompt HOT 1
- Prompt like "form prompt" from Enquirer
- Support configurable template data
- MultiSelect options spanning multiple columns HOT 1
- Pagination - shortcut key to paginate (page up or page down)
- Excuse me, how to remove the question mark at the beginning of the question? HOT 1
- mips64le not supported
- add a a whiptail/dialog replacement as an example script
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from survey.