forked from vmware-tanzu/tanzu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reconciliation wait for repository operations and package update (v…
…mware-tanzu#390) Signed-off-by: Marjan Alavi <malavi@vmware.com>
- Loading branch information
Showing
28 changed files
with
496 additions
and
267 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2021 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/briandowns/spinner" | ||
|
||
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/log" | ||
"github.com/vmware-tanzu/tanzu-framework/pkg/v1/tkg/tkgpackagedatamodel" | ||
) | ||
|
||
// DisplayProgress creates an spinner instance; keeps receiving the progress messages in the channel and displays those using the spinner until an error occurs | ||
func DisplayProgress(initialMsg string, pp *tkgpackagedatamodel.PackageProgress) error { | ||
var ( | ||
currMsg string | ||
s *spinner.Spinner | ||
err error | ||
) | ||
|
||
newSpinner := func() (*spinner.Spinner, error) { | ||
s = spinner.New(spinner.CharSets[9], 100*time.Millisecond) | ||
if err := s.Color("bgBlack", "bold", "fgWhite"); err != nil { | ||
return nil, err | ||
} | ||
return s, nil | ||
} | ||
if s, err = newSpinner(); err != nil { | ||
return err | ||
} | ||
|
||
writeProgress := func(s *spinner.Spinner, msg string) error { | ||
s.Stop() | ||
if s, err = newSpinner(); err != nil { | ||
return err | ||
} | ||
log.Infof("\n") | ||
s.Suffix = fmt.Sprintf(" %s", msg) | ||
s.Start() | ||
return nil | ||
} | ||
|
||
s.Suffix = fmt.Sprintf(" %s", initialMsg) | ||
s.Start() | ||
|
||
defer func() { | ||
s.Stop() | ||
}() | ||
for { | ||
select { | ||
case err := <-pp.Err: | ||
s.FinalMSG = "\n\n" | ||
return err | ||
case msg := <-pp.ProgressMsg: | ||
if msg != currMsg { | ||
if err := writeProgress(s, msg); err != nil { | ||
return err | ||
} | ||
currMsg = msg | ||
} | ||
case <-pp.Done: | ||
for msg := range pp.ProgressMsg { | ||
if msg == currMsg { | ||
continue | ||
} | ||
if err := writeProgress(s, msg); err != nil { | ||
return err | ||
} | ||
currMsg = msg | ||
} | ||
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
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
Oops, something went wrong.