-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
45 lines (40 loc) · 1.41 KB
/
cli.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
package cmdbiz
import (
"github.com/gookit/gcli/v3"
"github.com/gookit/gcli/v3/gflag"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/strutil"
"github.com/inhere/kite-go/internal/app"
"github.com/inhere/kite-go/pkg/lcproxy"
)
// CommonOpts some common vars struct
type CommonOpts struct {
Proxy bool
DryRun bool `flag:"name=dry-run;desc=run workflow, but dont real execute command;shorts=dry"`
Confirm bool
Workdir string
GitHost string
}
// BindCommonFlags for some git commands
func (co *CommonOpts) BindCommonFlags(c *gcli.Command) {
co.BindWorkdirDryRun(c)
co.BindProxyConfirm(c)
}
// BindProxyConfirm flags for some cli commands
func (co *CommonOpts) BindProxyConfirm(c *gcli.Command) {
c.BoolOpt2(&co.Proxy, "proxy,P", "manual enable set proxy ENV config(config:local_proxy)", gflag.WithValidator(func(val string) error {
if strutil.QuietBool(val) {
app.Lcp.Apply(func(lp *lcproxy.LocalProxy) {
c.Infoln("TIP: enabled to set proxy ENV vars, will set", lp.EnvKeys())
dump.NoLoc(lp)
})
}
return nil
}))
c.BoolOpt2(&co.Confirm, "confirm,C", "confirm ask before executing command")
}
// BindWorkdirDryRun flags for some cli commands
func (co *CommonOpts) BindWorkdirDryRun(c *gcli.Command) {
c.BoolOpt(&co.DryRun, "dry-run", "dry", false, "run workflow, but dont real execute command")
c.StrOpt(&co.Workdir, "workdir", "w", "", "the command workdir path, default is current dir")
}