Skip to content

Commit

Permalink
[CLC-220]: make configuration menu available in non-interactive mode …
Browse files Browse the repository at this point in the history
…as well (hazelcast#317)
  • Loading branch information
kutluhanmetin authored Aug 14, 2023
1 parent b4a5744 commit 6907906
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions clc/config/wizard/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package wizard
import (
"context"
"errors"
"fmt"
"os"
"sync/atomic"

tea "github.com/charmbracelet/bubbletea"
"github.com/hazelcast/hazelcast-commandline-client/clc"
"github.com/hazelcast/hazelcast-commandline-client/internal/terminal"
"github.com/hazelcast/hazelcast-go-client"
"github.com/spf13/pflag"

Expand Down Expand Up @@ -47,12 +50,19 @@ func (p *Provider) BindFlag(name string, flag *pflag.Flag) {
p.fp.Load().BindFlag(name, flag)
}

func maybeUnwrapStdout(ec plug.ExecContext) any {
if v, ok := ec.Stdout().(clc.NopWriteCloser); ok {
return v.W
}
return ec.Stdout()
}

func (p *Provider) ClientConfig(ctx context.Context, ec plug.ExecContext) (hazelcast.Config, error) {
if terminal.IsPipe(maybeUnwrapStdout(ec)) {
return hazelcast.Config{}, fmt.Errorf(`no configuration was provided and cannot display the configuration wizard; use the --config flag`)
}
cfg, err := p.fp.Load().ClientConfig(ctx, ec)
if err != nil {
if !ec.Interactive() {
return hazelcast.Config{}, err
}
// ask the config to the user
name, err := p.runWizard(ctx, ec)
if err != nil {
Expand Down

0 comments on commit 6907906

Please sign in to comment.