enbas/cmd/enbas/switch.go
Dan Anglin 2c5123253a
feat: add Enbas
Add Enbas code. So far Enbas can:

- Allow the user to register the application and log into GTS on their
  behalf. The scope is limited to read for now.
- Show instance details.
- Show local and remote accounts.
2024-02-23 09:44:57 +00:00

35 lines
751 B
Go

package main
import (
"flag"
"fmt"
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
)
type switchCommand struct {
*flag.FlagSet
toAccount string
}
func newSwitchCommand(name, summary string) *switchCommand {
command := switchCommand{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
toAccount: "",
}
command.StringVar(&command.toAccount, "to-account", "", "the account to switch to")
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
return &command
}
func (c *switchCommand) Execute() error {
if err := config.UpdateCurrentAccount(c.toAccount); err != nil {
return fmt.Errorf("unable to switch accounts; %w", err)
}
fmt.Printf("The current account is now set to %q.\n", c.toAccount)
return nil
}