Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2428 from ActiveState/mitchell/dx-1449
Initial dotprogress indicator for non-interactive mode.
- Loading branch information
Showing
8 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package progress | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/locale" | ||
"github.com/ActiveState/cli/internal/output" | ||
"github.com/ActiveState/cli/pkg/platform/runtime/setup/events" | ||
) | ||
|
||
const dotInterval = time.Second | ||
|
||
type DotProgressDigester struct { | ||
out output.Outputer | ||
spinner *output.Spinner | ||
success bool | ||
} | ||
|
||
// NewDotProgressIndicator prints dots at an interval while a runtime is being setup (during solve, | ||
// download, and install steps). | ||
// The primary goal is to indicate to various CI systems (or during non-interactive mode) that | ||
// progress is being made. | ||
func NewDotProgressIndicator(out output.Outputer) *DotProgressDigester { | ||
return &DotProgressDigester{out: out} | ||
} | ||
|
||
func (d *DotProgressDigester) Handle(event events.Eventer) error { | ||
switch event.(type) { | ||
case events.Start: | ||
d.spinner = output.StartSpinner(d.out, locale.T("setup_runtime"), time.Second) | ||
case events.Success: | ||
d.success = true | ||
} | ||
return nil | ||
} | ||
|
||
func (d *DotProgressDigester) Close() error { | ||
if d.spinner == nil { | ||
return errs.New("spinner not initialized") | ||
} | ||
if d.success { | ||
d.spinner.Stop(locale.T("progress_completed")) | ||
} else { | ||
d.spinner.Stop(locale.T("progress_failed")) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ActiveState/cli/internal/locale" | ||
"github.com/ActiveState/cli/internal/testhelpers/e2e" | ||
"github.com/ActiveState/cli/internal/testhelpers/tagsuite" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ProgressIntegrationTestSuite struct { | ||
tagsuite.Suite | ||
} | ||
|
||
func (suite *ProgressIntegrationTestSuite) TestProgress() { | ||
suite.OnlyRunForTags(tagsuite.Progress) | ||
ts := e2e.New(suite.T(), false) | ||
defer ts.Close() | ||
|
||
cp := ts.SpawnWithOpts( | ||
e2e.WithArgs("checkout", "ActiveState-CLI/small-python"), | ||
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"), | ||
) | ||
cp.Expect(locale.T("setup_runtime")) | ||
cp.Expect("Checked out") | ||
suite.Assert().NotContains(cp.TrimmedSnapshot(), "...") | ||
cp.ExpectExitCode(0) | ||
|
||
cp = ts.SpawnWithOpts( | ||
e2e.WithArgs("checkout", "ActiveState-CLI/small-python", "small-python2", "--non-interactive"), | ||
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"), | ||
) | ||
cp.Expect(locale.T("setup_runtime")) | ||
cp.Expect("...") | ||
cp.Expect("Checked out") | ||
cp.ExpectExitCode(0) | ||
} | ||
|
||
func TestProgressIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(ProgressIntegrationTestSuite)) | ||
} |