-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit.go
More file actions
59 lines (49 loc) · 1.64 KB
/
git.go
File metadata and controls
59 lines (49 loc) · 1.64 KB
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
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/completion"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewGitCommand creates a command for managing git repositories.
func NewGitCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "git",
Short: i18n.T("Manage git for applications"),
RunE: nil,
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
cmd.AddCommand(gitRemote(cmdr))
cmd.AddCommand(gitRemove(cmdr))
return cmd
}
func gitRemote(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
app string
remote string
force bool
}
cmd := &cobra.Command{
Use: "remote",
Short: i18n.T("Adds git remote of application to repository"),
RunE: func(_ *cobra.Command, _ []string) error {
return cmdr.GitRemote(app, flags.remote, flags.force)
},
}
cmd.Flags().StringVarP(&flags.remote, "remote", "r", "drycc", i18n.T("Name of remote to create"))
cmd.Flags().BoolVarP(&flags.force, "force", "f", false, i18n.T("Overwrite remote of the given name if it already exists"))
cmd.Flags().SortFlags = false
return cmd
}
func gitRemove(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Short: i18n.T("Removes git remote of application from repository"),
RunE: func(_ *cobra.Command, _ []string) error {
return cmdr.GitRemove(app)
},
}
return cmd
}