diff --git a/go.mod b/go.mod index a418291..938e81b 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ replace github.com/bougou/sail v0.0.0 => ./ require ( github.com/bougou/gopkg v0.0.0-20210915120156-d3a9c832dc24 + github.com/fatih/color v1.12.0 github.com/imdario/mergo v0.3.12 github.com/jinzhu/copier v0.3.2 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index b2f8da2..a37777f 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc= +github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -200,7 +202,11 @@ github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaW github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -396,6 +402,7 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/pkg/commands/apply/apply.go b/pkg/commands/apply/apply.go index 664d058..3dcb99e 100644 --- a/pkg/commands/apply/apply.go +++ b/pkg/commands/apply/apply.go @@ -72,7 +72,8 @@ func (o *ApplyOptions) Validate() error { } func (o *ApplyOptions) Run(args []string) error { - fmt.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + options.PrintColorHeader(o.TargetName, o.ZoneName) + zone := models.NewZone(o.sailOption, o.TargetName, o.ZoneName) if err := zone.Load(); err != nil { return err diff --git a/pkg/commands/confcreate/confcreate.go b/pkg/commands/confcreate/confcreate.go index 8eb7007..7ac2013 100644 --- a/pkg/commands/confcreate/confcreate.go +++ b/pkg/commands/confcreate/confcreate.go @@ -83,7 +83,7 @@ func (o *ConfCreateOptions) Validate() error { } func (o *ConfCreateOptions) Run() error { - fmt.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + options.PrintColorHeader(o.TargetName, o.ZoneName) zone := models.NewZone(o.sailOption, o.TargetName, o.ZoneName) if _, err := os.Stat(zone.ZoneDir); !os.IsNotExist(err) { diff --git a/pkg/commands/confupdate/confupdate.go b/pkg/commands/confupdate/confupdate.go index 47e351c..5ed31ed 100644 --- a/pkg/commands/confupdate/confupdate.go +++ b/pkg/commands/confupdate/confupdate.go @@ -81,7 +81,8 @@ func (o *ConfUpdateOptions) Validate() error { } func (o *ConfUpdateOptions) Run() error { - fmt.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + options.PrintColorHeader(o.TargetName, o.ZoneName) + zone := models.NewZone(o.sailOption, o.TargetName, o.ZoneName) if err := zone.Load(); err != nil { msg := fmt.Sprintf("zone.Load failed, err: %s", err) diff --git a/pkg/commands/upgrade/upgrade.go b/pkg/commands/upgrade/upgrade.go index e011849..f288f69 100644 --- a/pkg/commands/upgrade/upgrade.go +++ b/pkg/commands/upgrade/upgrade.go @@ -72,7 +72,8 @@ func (o *UpgradeOptions) Validate() error { } func (o *UpgradeOptions) Run(args []string) error { - fmt.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + options.PrintColorHeader(o.TargetName, o.ZoneName) + zone := models.NewZone(o.sailOption, o.TargetName, o.ZoneName) if err := zone.Load(); err != nil { return err diff --git a/pkg/commands/x/gencert/gencert.go b/pkg/commands/x/gencert/gencert.go index a2554bb..95e99f1 100644 --- a/pkg/commands/x/gencert/gencert.go +++ b/pkg/commands/x/gencert/gencert.go @@ -9,6 +9,7 @@ import ( "github.com/bougou/gopkg/cert" "github.com/bougou/gopkg/common" "github.com/bougou/sail/pkg/models" + "github.com/bougou/sail/pkg/options" "github.com/spf13/cobra" ) @@ -84,7 +85,7 @@ func (o *GenCertOptions) Validate() error { func (o *GenCertOptions) Run(args []string) error { fmt.Printf("output dir for certs: %s\n", o.OutputDir) if o.TargetName != "" && o.ZoneName != "" { - fmt.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + options.PrintColorHeader(o.TargetName, o.ZoneName) } if o.CAName != "" && len(o.Names) == 0 { diff --git a/pkg/options/header.go b/pkg/options/header.go new file mode 100644 index 0000000..15d2e90 --- /dev/null +++ b/pkg/options/header.go @@ -0,0 +1,14 @@ +package options + +import ( + "fmt" + + "github.com/fatih/color" +) + +func PrintColorHeader(targetName string, zoneName string) { + // d.Printf("👉 target: (%s), zone: (%s)\n", o.TargetName, o.ZoneName) + d := color.New(color.FgWhite, color.Bold, color.BgBlue) + s := fmt.Sprintf("👉 target: (%s), zone: (%s)", d.Sprint(targetName), d.Sprint(zoneName)) + fmt.Println(s) +}