Exemplo n.º 1
0
			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)
}
Exemplo n.º 2
0
var configCommand = &cobra.Command{
	Use:   "config",
	Short: "Configuration management",
}

var deleteConfigCommand = &cobra.Command{
	Use:   "delete <key>",
	Short: "Delete a property",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must specify a key")
		}

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

var getConfigCommand = &cobra.Command{
	Use:   "get <key>",
	Short: "Get a property",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must specify a key")
		}

		value := config.Get(args[0])

		fmt.Println(value)