Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
print color header
Browse files Browse the repository at this point in the history
  • Loading branch information
bougou committed Sep 16, 2021
1 parent 5b5fe5b commit abe0587
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/confcreate/confcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/confupdate/confupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/x/gencert/gencert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions pkg/options/header.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit abe0587

Please sign in to comment.