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

added history network selector #37

Merged
merged 2 commits into from
Aug 21, 2023
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
22 changes: 18 additions & 4 deletions cli/commands/resources/network/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/taubyte/tau-cli/singletons/config"
"github.com/taubyte/tau-cli/singletons/dreamland"
"github.com/taubyte/tau-cli/validate"
slices "github.com/taubyte/utils/slices/string"

networkFlags "github.com/taubyte/tau-cli/flags/network"
networkI18n "github.com/taubyte/tau-cli/i18n/network"
Expand All @@ -26,7 +27,6 @@ func (link) Select() cliCommon.Command {
)
}

// TODO: maybe save the old custom url when switching and prompt to use same as saved before
func _select(ctx *cli.Context) error {
// Setting string flag with value counts as two
if ctx.NumFlags() > 2 {
Expand All @@ -47,6 +47,10 @@ func _select(ctx *cli.Context) error {
return err
}

if !slices.Contains(profile.History, profile.Network) {
profile.History = append(profile.History, profile.Network)
}

case ctx.IsSet(networkFlags.Universe.Name):
dreamClient, err := dreamland.Client(ctx.Context)
if err != nil {
Expand Down Expand Up @@ -77,19 +81,26 @@ func _select(ctx *cli.Context) error {
networkSelections = append(networkSelections, common.DreamlandNetwork)
}

networkSelections = append(networkSelections, profile.History...)

prev := []string{}
if len(profile.NetworkType) > 0 {
prev = append(prev, profile.NetworkType)
}

profile.NetworkType = prompts.GetOrAskForSelection(ctx, "Network", prompts.NetworkPrompts, networkSelections, prev...)
if profile.NetworkType == common.RemoteNetwork {
network := prompts.GetOrAskForSelection(ctx, "Network", prompts.NetworkPrompts, networkSelections, prev...)
if network == common.RemoteNetwork {
profile.NetworkType = common.RemoteNetwork
profile.Network = prompts.GetOrRequireAString(ctx, "", prompts.FQDN, validate.FQDNValidator, profile.Network)
if err := validate.SeerFQDN(ctx.Context, profile.Network); err != nil {
return err
}

} else if profile.NetworkType == common.DreamlandNetwork {
if !slices.Contains(profile.History, profile.Network) {
profile.History = append(profile.History, profile.Network)
}

} else if network == common.DreamlandNetwork {
universes, err := dreamClient.Status()
if err != nil {
return fmt.Errorf("calling dreamland status failed with: %w", err)
Expand All @@ -104,6 +115,9 @@ func _select(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("universe selection failed with: %w", err)
}
} else {
profile.NetworkType = common.RemoteNetwork
profile.Network = network
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/login/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Select(ctx *cli.Context, name string, setDefault bool) error {
return err
}

env.SetSelectedNetwork(ctx, profile.Network)
env.SetSelectedNetwork(ctx, profile.NetworkType)
env.SetNetworkUrl(ctx, profile.Network)
return env.SetSelectedUser(ctx, name)
}
1 change: 1 addition & 0 deletions singletons/config/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestProfiles(t *testing.T) {
git_username: ""
git_email: ""
network: ""
history: []
`

configData, err := readConfig()
Expand Down
9 changes: 5 additions & 4 deletions singletons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ type Profile struct {

// TODO get from config when verifying token
// may need to fake in tests
GitUsername string `yaml:"git_username"`
GitEmail string `yaml:"git_email"`
NetworkType string `yaml:"type,omitempty"`
Network string `yaml:"network"`
GitUsername string `yaml:"git_username"`
GitEmail string `yaml:"git_email"`
NetworkType string `yaml:"type,omitempty"`
Network string `yaml:"network"`
History []string `yaml:"history"`
}

type Project struct {
Expand Down