Esempio n. 1
0
func ListRemotes(config config.Config) prettycli.Output {
	agents := config.Remotes()
	if len(agents) == 0 {
		return prettycli.PlainOutput{"No remotes"}
	}

	output := prettycli.ListOutput{Labels: []string{"Active", "Name", "Endpoint"}}
	for _, r := range config.Remotes() {
		activeMarker := ""
		if config.Active() != nil && *config.Active() == r {
			activeMarker = "*"
		}

		output.AddRow(map[string]string{
			"Active":   activeMarker,
			"Name":     r.Name,
			"Endpoint": r.Endpoint,
		})
	}
	return &output
}
Esempio n. 2
0
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
}