|
| 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 | +} |
0 commit comments