Ejemplo n.º 1
0
			passwordInBytes, err := terminal.ReadPassword(int(syscall.Stdin))
			fmt.Println()

			if err != nil {
				return err
			}
			password = string(passwordInBytes)
		}

		token, err := registry.Login(username, password)

		if err != nil {
			return err
		}

		config.Set("token", token)
		config.Save()

		fmt.Println()
		fmt.Println("Welcome!")
		fmt.Println()

		return nil
	},
}

func init() {
	loginCommand.Flags().StringP("username", "u", "", "Username")
	loginCommand.Flags().StringP("password", "p", "", "Password")

	rootCmd.AddCommand(loginCommand)
Ejemplo n.º 2
0
	Short: "List all the properties",
	Run: func(cmd *cobra.Command, args []string) {
		properties := config.List()

		for k, v := range properties {
			fmt.Println(k + " = " + v)
		}
	},
}

var setConfigCommand = &cobra.Command{
	Use:   "set <key> <value>",
	Short: "Set a property",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) < 2 {
			return errors.New("You must specify a key and value")
		}

		config.Set(args[0], args[1])
		return config.Save()
	},
}

func init() {
	configCommand.AddCommand(deleteConfigCommand)
	configCommand.AddCommand(getConfigCommand)
	configCommand.AddCommand(listConfigCommand)
	configCommand.AddCommand(setConfigCommand)
	rootCmd.AddCommand(configCommand)
}