-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (97 loc) · 2.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"errors"
"fmt"
"log"
"os"
"regexp"
"github.com/AlecAivazis/survey/v2"
"github.com/rarneson/milestones/github"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "close",
Usage: "close a milestone across your repositories",
Action: func(c *cli.Context) error {
return nil
},
},
{
Name: "add",
Usage: "add a milestone to your repositories",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "Your personal access token for GitHub",
},
&cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Value: "github.com",
EnvVars: []string{"MILESTONES_GIT_SERVER"},
Usage: "GitHub server",
},
&cli.StringFlag{
Name: "repos",
Usage: "comma separated list of repositories in the format org/repo",
EnvVars: []string{"MILESTONES_REPOS"},
},
},
Action: addAction,
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func addAction(c *cli.Context) error {
gitOptions := github.Options{
Token: c.String("token"),
Server: c.String("server"),
}
g, err := github.New(gitOptions)
if err != nil {
return err
}
// fmt.Printf("%+v\n", gitOptions)
var questions = []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{Message: "What is the name of this milestone?"},
Validate: survey.Required,
},
{
Name: "dueDate",
Prompt: &survey.Input{Message: "What is the date this milestone will end (yyyy-mm-dd)?"},
Validate: survey.ComposeValidators(survey.Required, validateDateFormat),
},
}
answers := struct {
Name string
DueDate string
}{}
// ask the common questions
err = survey.Ask(questions, &answers)
if err != nil {
return err
}
fmt.Printf("%+v", g) // eventually, g.AddMilestones
return nil
}
func validateDateFormat(val interface{}) error {
date := val.(string)
match, err := regexp.MatchString(`^[\d]{4}-[\d]{2}-[\d]{2}$`, date)
if err != nil {
return err
}
if match == false {
return errors.New("Due date needs to be in the format yyyy-mm-dd")
}
return nil
}