Giter VIP home page Giter VIP logo

Comments (4)

mholt avatar mholt commented on May 30, 2024

I implemented this simply:

func askOne(p survey.Prompt) string {
	answers, err := survey.Ask([]*survey.Question{{Name: "q1", Prompt: p}})
	if err != nil {
		log.Fatal(err) // or whatever
	}
	return answers["q1"]
}

// Usage:
answer := askOne(&survey.Choice{
	Message: "...?",
	Choices: []string{"..."},
})

But it might be nice to see this available in the package itself.

from survey.

AlecAivazis avatar AlecAivazis commented on May 30, 2024

I like this idea - if you had time to submit a PR I would gladly merge it in. I would do it myself but I think I will be pretty busy with the other issues.

from survey.

AlecAivazis avatar AlecAivazis commented on May 30, 2024

Just curious, what sort of logic needs to happen? I'm wondering if there is something survey could be providing that would better support what you needed. The only usecase I could think of where one would need to change the question based on previous answers which I am still thinking on the right API for. If you have something different, I'd love to hear.

from survey.

mholt avatar mholt commented on May 30, 2024

It's application-specific. In one case, I quit entirely ("are you sure you want to continue?" kind of thing). But yes, other times it is to add an extra follow-up question or to skip questions.

So I actually use your package more for getting input rather than doing an actual survey. I like how it formats the output and does multiple-choice, especially. Very pleasing to read and use. So I find myself asking one question at a time rather than batching them.

So I dunno how complicated you want your API to get, but if you felt like users need a more comprehensive solution you could consider something like a "computation graph" but with questions instead of computations. For each question, you'd need a function that maps possible answers to next questions.

from survey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.