// Send get specified user from prompt and actually send it to the target func Send(ipmsg *goipmsg.IPMSG) { userIdx := []string{} i := 0 m := make(map[int]string) for k, _ := range Users { i++ fmt.Printf("%d %v\n", i, k) userIdx = append(userIdx, strconv.Itoa(i)) m[i] = k } chosen := (&prompter.Prompter{ Choices: userIdx, UseDefault: false, Message: "Choose the user to send message>", IgnoreCase: true, }).Prompt() i, _ = strconv.Atoi(chosen) key := m[i] promptMessage := fmt.Sprintf("Enter message(to %v)", key) message := prompter.Prompt(promptMessage, "") cd := Users[key] addr := cd.Addr cmd := goipmsg.SENDMSG cmd.SetOpt(goipmsg.SECRET) err := ipmsg.SendMSG(addr, message, cmd) if err != nil { panic(err) } fmt.Println("sent SENDMSG") }
func ExamplePrompt() { answer := prompter.Prompt("Enter your twitter ID", "") _ = answer fmt.Println("Songmu") fmt.Printf("Hi Songmu!") // Output: // Enter your twitter ID: Songmu // Hi Songmu! }
func runSetup(ctx *cli.Context) { var err error env := config.NewEnvironment() force := ctx.Bool("force") env.Tz = prompter.Prompt("Timezone", env.Tz) env.SitesDir, err = promptForDir("Sites directory", env.SitesDir) if err != nil { util.Fatal(err) } env.DataDir, err = promptForDir("Database storage directory", env.DataDir) if err != nil { util.Fatal(err) } err = env.Check() if err != nil { util.Fatal(err) } acts := []step.ConfigStep{ step.VariablesStep, } if env.RequiresMachine() { acts = append(acts, step.MachineStep) acts = append(acts, step.NfsServerStep) acts = append(acts, step.NfsClientStep) } acts = append(acts, step.ServicesStep) acts = append(acts, step.NewDnsAction()) for _, act := range acts { needs := act.NeedsRun(env) if needs || force { util.Successf("Running %s", act.GetName()) err := act.Run(env) if err != nil { util.Fatal(err) } } else { util.Successf("Skipping %s", act.GetName()) } } util.Success("Setup complete") }
func promptForDir(name string, def string) (dir string, err error) { dir = prompter.Prompt(name, def) dir, err = homedir.Expand(dir) if err != nil { return } exists, err := util.DirExists(dir) if !exists { create := prompter.YN(fmt.Sprintf("%s does not exist. Create?", dir), false) if create { err = os.MkdirAll(dir, 0755) return } err = errors.New("Did not create directory") } return }