Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
(feat): usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Oct 9, 2020
1 parent ad182be commit d77c260
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/inputfilesuggestion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"fmt"
"path/filepath"

"github.com/AlecAivazis/survey/v2"
)

func suggestFiles(toComplete string) []string {
files, _ := filepath.Glob(toComplete + "*")
return files
}

// the questions to ask
var q = []*survey.Question{
{
Name: "file",
Prompt: &survey.Input{
Message: "Which file should be read?",
Suggest: suggestFiles,
Help: "Any file, may not even exit yet",
},
Validate: survey.Required,
},
}

func main() {
answers := struct {
File string
}{}

// ask the question
err := survey.Ask(q, &answers)

if err != nil {
fmt.Println(err.Error())
return
}
// print the answers
fmt.Printf("File chosen %s.\n", answers.File)
}

0 comments on commit d77c260

Please sign in to comment.