Skip to content

Commit

Permalink
Merge pull request #316 from HarrisonWAffel/check-for-no-servers
Browse files Browse the repository at this point in the history
Display message when no servers are available
  • Loading branch information
HarrisonWAffel authored Jun 8, 2022
2 parents 01a46c6 + e5566ac commit 4196225
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func serverDelete(ctx *cli.Context) error {
return err
}

if err := validateServersConfig(cf); err != nil {
return err
}

var serverName string
if ctx.NArg() == 1 {
serverName = ctx.Args().First()
Expand Down Expand Up @@ -114,6 +118,10 @@ func serverLs(ctx *cli.Context) error {
return err
}

if err := validateServersConfig(cf); err != nil {
return err
}

writer := NewTableWriter([][]string{
{"CURRENT", "Current"},
{"NAME", "Name"},
Expand Down Expand Up @@ -144,6 +152,10 @@ func serverSwitch(ctx *cli.Context) error {
return err
}

if err := validateServersConfig(cf); err != nil {
return err
}

var serverName string
if ctx.NArg() == 1 {
serverName = ctx.Args().First()
Expand Down Expand Up @@ -238,3 +250,10 @@ func getServerNames(cf config.Config) []string {
sort.Strings(serverNames)
return serverNames
}

func validateServersConfig(cnf config.Config) error {
if len(cnf.Servers) == 0 {
return errors.New("no servers are currently configured")
}
return nil
}

0 comments on commit 4196225

Please sign in to comment.