Skip to content

Commit 123769f

Browse files
authored
Use a non-interactive progress writer in non-TTY environments (#405)
* Add isatty dep * Refactor text.Progress to not use interactive spinners when in non-TTY environments.
1 parent 0886206 commit 123769f

File tree

11 files changed

+92
-53
lines changed

11 files changed

+92
-53
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ require (
4141
github.com/google/jsonapi v0.0.0-20201022225600-f822737867f6 // indirect
4242
github.com/klauspost/compress v1.13.5 // indirect
4343
github.com/klauspost/pgzip v1.2.5 // indirect
44-
github.com/mattn/go-isatty v0.0.13 // indirect
44+
github.com/mattn/go-isatty v0.0.14 // indirect
4545
github.com/nwaples/rardecode v1.1.2 // indirect
4646
github.com/pierrec/lz4/v4 v4.1.8 // indirect
4747
github.com/rogpeppe/go-internal v1.8.0 // indirect

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
7070
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
7171
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
7272
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
73+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
74+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
7375
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
7476
github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU=
7577
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
@@ -135,6 +137,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
135137
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
136138
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
137139
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
140+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
138141
golang.org/x/sys v0.0.0-20210903071746-97244b99971b h1:3Dq0eVHn0uaQJmPO+/aYPI/fRMqdrVDbu7MQcku54gg=
139142
golang.org/x/sys v0.0.0-20210903071746-97244b99971b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
140143
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=

pkg/commands/compute/build.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ func NewBuildCommand(parent cmd.Registerer, client api.HTTPClient, globals *conf
9797

9898
// Exec implements the command interface.
9999
func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
100-
var progress text.Progress
101-
if c.Globals.Verbose() {
102-
progress = text.NewVerboseProgress(out)
103-
} else {
104-
progress = text.NewQuietProgress(out)
105-
}
100+
progress := text.NewProgress(out, c.Globals.Verbose())
106101

107102
defer func(errLog errors.LogInterface) {
108103
if err != nil {

pkg/commands/compute/deploy.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,7 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
211211

212212
// RESOURCE CREATION...
213213

214-
var progress text.Progress
215-
if verbose {
216-
progress = text.NewVerboseProgress(out)
217-
} else {
218-
progress = text.NewQuietProgress(out)
219-
}
220-
214+
progress := text.NewProgress(out, c.Globals.Verbose())
221215
undoStack := undo.NewStack()
222216

223217
defer func(errLog errors.LogInterface, progress text.Progress) {
@@ -418,13 +412,7 @@ func manageNoServiceIDFlow(
418412
text.Break(out)
419413
}
420414

421-
var progress text.Progress
422-
423-
if verbose {
424-
progress = text.NewVerboseProgress(out)
425-
} else {
426-
progress = text.NewQuietProgress(out)
427-
}
415+
progress := text.NewProgress(out, verbose)
428416

429417
// There is no service and so we'll do a one time creation of the service
430418
//

pkg/commands/compute/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
212212
text.Break(out)
213213

214214
if !c.Globals.Verbose() {
215-
progress = text.NewQuietProgress(out)
215+
progress = text.NewProgress(out, false)
216216
}
217217

218218
_, err = exec.LookPath("git")

pkg/commands/compute/pack.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ func NewPackCommand(parent cmd.Registerer, globals *config.Data) *PackCommand {
3838

3939
// Exec implements the command interface.
4040
func (c *PackCommand) Exec(in io.Reader, out io.Writer) (err error) {
41-
var progress text.Progress
42-
if c.Globals.Verbose() {
43-
progress = text.NewVerboseProgress(out)
44-
} else {
45-
progress = text.NewQuietProgress(out)
46-
}
41+
progress := text.NewProgress(out, c.Globals.Verbose())
4742

4843
defer func(errLog errors.LogInterface) {
4944
if err != nil {

pkg/commands/compute/serve.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
8888
text.Break(out)
8989
}
9090

91-
var progress text.Progress
92-
if c.Globals.Verbose() {
93-
progress = text.NewVerboseProgress(out)
94-
} else {
95-
progress = text.NewQuietProgress(out)
96-
}
91+
progress := text.NewProgress(out, c.Globals.Verbose())
9792

9893
bin, err := getViceroy(progress, out, c.viceroyVersioner)
9994
if err != nil {

pkg/commands/compute/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *UpdateCommand) Exec(in io.Reader, out io.Writer) (err error) {
6565
return err
6666
}
6767

68-
progress := text.NewQuietProgress(out)
68+
progress := text.NewProgress(out, c.Globals.Verbose())
6969
defer func() {
7070
if err != nil {
7171
c.Globals.ErrLog.AddWithContext(err, map[string]interface{}{

pkg/commands/configure/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) (err error) {
9696

9797
text.Break(out)
9898

99-
progress := text.NewQuietProgress(out)
99+
progress := text.NewProgress(out, c.Globals.Verbose())
100100
defer func() {
101101
if err != nil {
102102
c.Globals.ErrLog.Add(err)

pkg/commands/update/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
5151
text.Output(out, "Latest version: %s", latest)
5252
text.Break(out)
5353

54-
progress := text.NewQuietProgress(out)
54+
progress := text.NewProgress(out, c.Globals.Verbose())
5555
progress.Step("Updating versioning information...")
5656

5757
err = c.Globals.File.Load(c.Globals.File.CLI.RemoteConfig, c.client, config.ConfigRequestTimeout, config.FilePath)

0 commit comments

Comments
 (0)