mlisting

Mailing list service

git clone git://git.lin.moe/go/mlisting.git

 1package admin
 2
 3import (
 4	"bufio"
 5	"strings"
 6
 7	rcmd "git.lin.moe/go/mlisting/cmd"
 8	"github.com/spf13/cobra"
 9)
10
11var cmd *cobra.Command
12
13func init() {
14	cmd = &cobra.Command{
15		Use:     "admin",
16		Aliases: []string{"adm"},
17		Short:   "administration commands",
18	}
19
20	rcmd.Cmd.AddCommand(cmd)
21}
22
23func ask(cmd *cobra.Command, msg string, default_val bool) bool {
24	reader := bufio.NewReader(cmd.InOrStdin())
25	cmd.PrintErr(msg)
26	for {
27		s, _ := reader.ReadString('\n')
28		s = strings.TrimSuffix(s, "\n")
29		s = strings.ToLower(s)
30		if len(s) > 1 {
31			cmd.PrintErrf("Please enter Y or N")
32			continue
33		} else if len(s) == 0 {
34			return default_val
35		}
36		if strings.Compare(s, "n") == 0 {
37			return false
38		} else if strings.Compare(s, "y") == 0 {
39			return true
40		} else {
41			continue
42		}
43	}
44}