Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change session to use the same spinner reference #2943

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Fix config file migration to void leaving end of file content chunks
- Change session print loop to block until all events are handled.
- Handle "No records were found in keyring" message when checking keys.
- [#2941](https://github.com/ignite/cli/issues/2941) Fix session to use the same spinner referece.
- [#2922](https://github.com/ignite/cli/pull/2922) Network commands check for latest config version before building the chain binary.

## [`v0.24.1`](https://github.com/ignite/cli/releases/tag/v0.24.1)
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ https://docs.ignite.com/migration`, sc.Version.String(),
return sc, nil
}

func printSection(session cliui.Session, title string) error {
func printSection(session *cliui.Session, title string) error {
return session.Printf("------\n%s\n------\n\n", title)
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_campaign_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func networkCampaignListHandler(cmd *cobra.Command, _ []string) error {
}

// renderCampaignSummaries writes into the provided out, the list of summarized campaigns
func renderCampaignSummaries(campaigns []networktypes.Campaign, session cliui.Session) error {
func renderCampaignSummaries(campaigns []networktypes.Campaign, session *cliui.Session) error {
var campaignEntries [][]string

for _, c := range campaigns {
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_chain_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func networkChainInitHandler(cmd *cobra.Command, args []string) error {
}

// askValidatorInfo prompts to the user questions to query validator information
func askValidatorInfo(cmd *cobra.Command, session cliui.Session, stakeDenom string) (chain.Validator, error) {
func askValidatorInfo(cmd *cobra.Command, session *cliui.Session, stakeDenom string) (chain.Validator, error) {
var (
account, _ = cmd.Flags().GetString(flagValidatorAccount)
website, _ = cmd.Flags().GetString(flagValidatorWebsite)
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_chain_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func networkChainJoinHandler(cmd *cobra.Command, args []string) error {

// askPublicAddress prepare questions to interactively ask for a publicAddress
// when peer isn't provided and not running through chisel proxy.
func askPublicAddress(cmd *cobra.Command, session cliui.Session) (publicAddress string, err error) {
func askPublicAddress(cmd *cobra.Command, session *cliui.Session) (publicAddress string, err error) {
ctx := cmd.Context()

if gitpod.IsOnGitpod() {
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_chain_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func networkChainListHandler(cmd *cobra.Command, _ []string) error {
}

// renderLaunchSummaries writes into the provided out, the list of summarized launches
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session cliui.Session, advanced bool) error {
func renderLaunchSummaries(chainLaunches []networktypes.ChainLaunch, session *cliui.Session, advanced bool) error {
header := LaunchSummaryHeader
if advanced {
// advanced information show the campaign ID, type of network and rewards for incentivized testnet
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_chain_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewNetworkChainShow() *cobra.Command {
return c
}

func networkChainLaunch(cmd *cobra.Command, args []string, session cliui.Session) (NetworkBuilder, uint64, error) {
func networkChainLaunch(cmd *cobra.Command, args []string, session *cliui.Session) (NetworkBuilder, uint64, error) {
nb, err := newNetworkBuilder(cmd, CollectEvents(session.EventBus()))
if err != nil {
return nb, 0, err
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/network_request_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func networkRequestListHandler(cmd *cobra.Command, args []string) error {
// renderRequestSummaries writes into the provided out, the list of summarized requests
func renderRequestSummaries(
requests []networktypes.Request,
session cliui.Session,
session *cliui.Session,
addressPrefix string,
) error {
requestEntries := make([][]string, 0)
Expand Down
4 changes: 2 additions & 2 deletions ignite/cmd/network_reward_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func networkRewardRelease(cmd *cobra.Command, args []string) (err error) {
func createClient(
cmd *cobra.Command,
n network.Network,
session cliui.Session,
session *cliui.Session,
launchID uint64,
nodeAPI,
spnChainID string,
Expand Down Expand Up @@ -254,7 +254,7 @@ func createClient(
return chainRelayer, spnRelayer, err
}

func printRelayerOptions(session cliui.Session, obj, chainID, option string) {
func printRelayerOptions(session *cliui.Session, obj, chainID, option string) {
if obj != "" {
session.Printf("%s The chain %s already have a %s: %s\n",
icons.Bullet,
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/relayer_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func relayerConfigureHandler(cmd *cobra.Command, _ []string) (err error) {
func initChain(
cmd *cobra.Command,
r relayer.Relayer,
session cliui.Session,
session *cliui.Session,
name,
accountName,
rpcAddr,
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func gitChangesConfirmPreRunHandler(cmd *cobra.Command, args []string) error {
return confirmWhenUncommittedChanges(session, appPath)
}

func confirmWhenUncommittedChanges(session cliui.Session, appPath string) error {
func confirmWhenUncommittedChanges(session *cliui.Session, appPath string) error {
cleanState, err := xgit.AreChangesCommitted(appPath)
if err != nil {
return err
Expand Down
18 changes: 11 additions & 7 deletions ignite/pkg/cliui/clispinner/clispinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/briandowns/spinner"
)

// DefaultText defines the default spinner text.
const DefaultText = "Initializing..."

var (
refreshRate = time.Millisecond * 200
charset = spinner.CharSets[4]
Expand Down Expand Up @@ -39,17 +42,18 @@ func New(options ...Option) *Spinner {
apply(&o)
}

underlyingSpinnerOptions := []spinner.Option{spinner.WithColor(spinnerColor)}
if o.writer != nil {
underlyingSpinnerOptions = append(underlyingSpinnerOptions, spinner.WithWriter(o.writer))
spOptions := []spinner.Option{
spinner.WithColor(spinnerColor),
spinner.WithSuffix(" " + DefaultText),
}

sp := spinner.New(charset, refreshRate, underlyingSpinnerOptions...)
if o.writer != nil {
spOptions = append(spOptions, spinner.WithWriter(o.writer))
}

s := &Spinner{
sp: sp,
return &Spinner{
sp: spinner.New(charset, refreshRate, spOptions...),
}
return s.SetText("Initializing...")
}

// SetText sets the text for spinner.
Expand Down
12 changes: 6 additions & 6 deletions ignite/pkg/cliui/cliui.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func StartSpinner() Option {
}

// New creates a new Session.
func New(options ...Option) Session {
func New(options ...Option) *Session {
session := Session{
ev: events.NewBus(),
wg: &sync.WaitGroup{},
Expand Down Expand Up @@ -105,9 +105,9 @@ func New(options ...Option) Session {
// The main loop that prints the events uses a wait group to block
// the session end until all the events are printed.
session.wg.Add(1)
go session.handleEvents(session.wg)
go session.handleEvents()

return session
return &session
}

// EventBus returns the event bus of the session.
Expand Down Expand Up @@ -138,7 +138,7 @@ func (s Session) NewOutput(label string, color uint8) uilog.Output {
}

// StartSpinner starts the spinner.
func (s Session) StartSpinner(text string) {
func (s *Session) StartSpinner(text string) {
if s.spinner == nil {
s.spinner = clispinner.New(clispinner.WithWriter(s.out.Stdout()))
}
Expand Down Expand Up @@ -224,8 +224,8 @@ func (s Session) End() {
s.wg.Wait()
}

func (s Session) handleEvents(wg *sync.WaitGroup) {
defer wg.Done()
func (s *Session) handleEvents() {
defer s.wg.Done()

stdout := s.out.Stdout()

Expand Down