This repository was archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad182be
commit d77c260
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |