func AddRemote(config config.Config, name string, token []byte) (prettycli.Output, error) { if !format.MatchString(name) { return prettycli.PlainOutput{}, errors.New("Invalid name") } if _, err := config.Get(name); err == nil { return prettycli.PlainOutput{}, errors.New("Name already exists") } trimmedToken := strings.TrimSpace(string(token)) if err := config.Save(name, trimmedToken); err != nil { return prettycli.PlainOutput{}, err } if len(config.Remotes()) == 1 { config.SetActive(name) } s := "Successfully added!" if config.Active() != nil { s += fmt.Sprintf(" '%s' is your active remote.", config.Active().Name) } return prettycli.PlainOutput{s}, nil }
func SetActiveRemote(config config.Config, name string) (prettycli.Output, error) { if err := config.SetActive(name); err != nil { return prettycli.PlainOutput{}, err } return prettycli.PlainOutput{fmt.Sprintf("'%s' is now your active remote!", name)}, nil }