Skip to content

Commit bd85af3

Browse files
committed
feat: flow and commands defines
1 parent 2078090 commit bd85af3

17 files changed

+825
-42
lines changed

cmd/gitlab-flow/commands.go

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package main
2+
3+
import (
4+
"github.com/yeqown/gitlab-flow/internal/conf"
5+
6+
"github.com/urfave/cli/v2"
7+
"github.com/yeqown/log"
8+
)
9+
10+
func getInitCommand() *cli.Command {
11+
return &cli.Command{
12+
Name: "init",
13+
Usage: "initialize gitlab-flow, generate default config file and sqlite DB " +
14+
"related to the path (default path is `~/.gitlab-flow/`)",
15+
Category: "tools",
16+
Flags: []cli.Flag{
17+
&cli.StringFlag{
18+
Name: "access_token",
19+
Aliases: []string{"s"},
20+
Required: true,
21+
Usage: "access_token is secret for user to access gitlab API.",
22+
},
23+
&cli.StringFlag{
24+
Name: "gitlab_host",
25+
Aliases: []string{"h"},
26+
Required: true,
27+
Usage: "gitlab_host is the domain of YOUR gitlab server.",
28+
},
29+
&cli.StringFlag{
30+
Name: "conf_path",
31+
Aliases: []string{"c"},
32+
Value: conf.DefaultConfPath(),
33+
Required: true,
34+
Usage: "conf_path is the directory which contains your config and local database.",
35+
},
36+
},
37+
ArgsUsage: "gitlab-flow init -s ACCESS_TOKEN -h GITLAB_HOST [-c CONF_PATH]",
38+
Action: func(c *cli.Context) error {
39+
accessToken := c.String("access_token")
40+
host := c.String("gitlab_host")
41+
confPath := c.String("conf_path")
42+
43+
cfg := conf.Default()
44+
cfg.AccessToken = accessToken
45+
cfg.GitlabAPIURL = host
46+
47+
if err := conf.Save(confPath, cfg, nil); err != nil {
48+
log.Errorf("gitlab-flow initialize failed: %v", err)
49+
return err
50+
}
51+
52+
log.Infof("gitlab-flow has initialized. conf path is %s", confPath)
53+
return nil
54+
},
55+
}
56+
}
57+
58+
// getFeatureCommand
59+
// gitlab-flow feature [command options] -c --conf_path
60+
func getFeatureCommand() *cli.Command {
61+
return &cli.Command{
62+
Name: "feature",
63+
Usage: "managing the works in developing.",
64+
ArgsUsage: "gitlab-flow hotfix [-c, --conf_path] [-v, --debug]",
65+
Category: "feature",
66+
Flags: []cli.Flag{
67+
&cli.StringFlag{
68+
Name: "conf_path",
69+
Aliases: []string{"c"},
70+
Value: conf.DefaultConfPath(),
71+
Usage: "-c, --conf_path",
72+
Required: true,
73+
},
74+
&cli.BoolFlag{
75+
Name: "debug",
76+
Aliases: []string{"v"},
77+
Value: false,
78+
Usage: "-v, --debug ",
79+
Required: false,
80+
},
81+
},
82+
Subcommands: getFeatureSubCommands(),
83+
}
84+
}
85+
86+
// gitlab-flow hotfix [command options] -p --specProject
87+
func getHotfixCommand() *cli.Command {
88+
return &cli.Command{
89+
Name: "hotfix",
90+
Usage: "managing the works in hotfix.",
91+
ArgsUsage: "gitlab-flow hotfix [-c, --conf_path] [-v, --debug]",
92+
Category: "hotfix",
93+
Flags: []cli.Flag{
94+
&cli.StringFlag{
95+
Name: "conf_path",
96+
Aliases: []string{"c"},
97+
Value: conf.DefaultConfPath(),
98+
Usage: "-c, --conf_path",
99+
Required: true,
100+
},
101+
&cli.BoolFlag{
102+
Name: "debug",
103+
Aliases: []string{"v"},
104+
Value: false,
105+
Usage: "-v, --debug ",
106+
Required: false,
107+
},
108+
},
109+
Subcommands: getHotfixSubCommands(),
110+
}
111+
}
112+
113+
// getDashCommand
114+
func getDashCommand() *cli.Command {
115+
return &cli.Command{
116+
Name: "dash",
117+
Usage: "gitlab-flow dash",
118+
Description: "overview of local development",
119+
Category: "dash",
120+
Flags: []cli.Flag{
121+
&cli.StringFlag{
122+
Name: "conf_path",
123+
Aliases: []string{"c"},
124+
Value: conf.DefaultConfPath(),
125+
Usage: "-c, --conf_path",
126+
Required: true,
127+
},
128+
&cli.BoolFlag{
129+
Name: "debug",
130+
Aliases: []string{"v"},
131+
Value: false,
132+
Usage: "-v, --debug ",
133+
Required: false,
134+
},
135+
},
136+
Subcommands: getDashSubCommands(),
137+
}
138+
}

cmd/gitlab-flow/commands_dash.go

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/yeqown/gitlab-flow/internal/types"
7+
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
func getDashSubCommands() cli.Commands {
12+
return cli.Commands{
13+
getDashFeatureDetailSubCommand(),
14+
getDashProjectDetailSubCommand(),
15+
getDashMilestoneOverviewSubCommand(),
16+
}
17+
}
18+
19+
// gitlab-flow dash feature -b featureBranchName
20+
func getDashFeatureDetailSubCommand() *cli.Command {
21+
return &cli.Command{
22+
Name: "feature",
23+
Aliases: []string{"f"},
24+
Usage: "查看一个迭代分支的详情(MR清单,Issue清单,Branch清单,关联的Milestone)",
25+
ArgsUsage: "@branchName",
26+
Category: "dash",
27+
Flags: []cli.Flag{
28+
&cli.StringFlag{
29+
Name: "branchName",
30+
Aliases: []string{"b"},
31+
Usage: "迭代分支名",
32+
Required: true,
33+
},
34+
},
35+
Action: func(c *cli.Context) error {
36+
confPath := c.String("conf_path")
37+
debug := c.Bool("debug")
38+
39+
featureBranchName := c.String("branchName")
40+
data, err := getDash(confPath, debug).FeatureDetail(featureBranchName)
41+
if err != nil {
42+
return err
43+
}
44+
fmt.Printf("%s\n", data)
45+
return nil
46+
},
47+
}
48+
}
49+
50+
// gitlab-flow dash milestone -m milestoneName
51+
func getDashMilestoneOverviewSubCommand() *cli.Command {
52+
return &cli.Command{
53+
Name: "milestone",
54+
Aliases: []string{"m"},
55+
Usage: "overview of one milestone, includes: merges, issues, branch",
56+
ArgsUsage: "@milestoneName",
57+
Category: "dash",
58+
Flags: []cli.Flag{
59+
&cli.StringFlag{
60+
Name: "milestone_name",
61+
Aliases: []string{"m"},
62+
Usage: "-m, --milestone_name",
63+
Required: true,
64+
},
65+
&cli.StringFlag{
66+
Name: "filter_branch",
67+
Aliases: []string{"f"},
68+
Usage: "-f, --filter_branch @branchName default: master",
69+
DefaultText: types.MasterBranch.String(),
70+
},
71+
},
72+
Action: func(c *cli.Context) error {
73+
milestoneName := c.String("milestone_name")
74+
filterBranchName := c.String("filter_branch")
75+
confPath := c.String("conf_path")
76+
debug := c.Bool("debug")
77+
data, err := getDash(confPath, debug).MilestoneOverview(milestoneName, filterBranchName)
78+
if err != nil {
79+
return err
80+
}
81+
fmt.Printf("%s\n", data)
82+
return nil
83+
},
84+
}
85+
}
86+
87+
// gitlab-flow dash project
88+
func getDashProjectDetailSubCommand() *cli.Command {
89+
return &cli.Command{
90+
Name: "project",
91+
Aliases: []string{"p"},
92+
Usage: "-p, --project",
93+
ArgsUsage: "-p @projectName, default current project",
94+
Category: "dash",
95+
Flags: []cli.Flag{
96+
&cli.BoolFlag{
97+
Name: "open_web",
98+
Aliases: []string{"o"},
99+
Usage: "-o, --open_web",
100+
Required: false,
101+
Value: false,
102+
},
103+
},
104+
Action: func(c *cli.Context) error {
105+
confPath := c.String("conf_path")
106+
debug := c.Bool("debug")
107+
open := c.Bool("open_web")
108+
data, err := getDash(confPath, debug).ProjectDetail(open)
109+
if err != nil {
110+
return err
111+
}
112+
fmt.Printf("%s\n", data)
113+
return nil
114+
},
115+
}
116+
}

0 commit comments

Comments
 (0)