Skip to content

Instantly share code, notes, and snippets.

@ninedraft
Last active October 8, 2018 18:44
Show Gist options
  • Save ninedraft/304e0a5e7d94935d2b574b5b33b58dd1 to your computer and use it in GitHub Desktop.
Save ninedraft/304e0a5e7d94935d2b574b5b33b58dd1 to your computer and use it in GitHub Desktop.
import (
gpflag "github.com/octago/sflags/gen/gpflag"
cobra "github.com/spf13/cobra"
)
type Flags struct {
// flag definitions here
// https://github.com/octago/sflags#flags-based-on-structures------
}
func Command() *cobra.Command {
var flags Flags // default values can be defined here
var cmd = &cobra.Command{
Use: "command",
Run: func(cmd *cobra.Command, args []string) {
// write your code here
},
}
if err := gpflag.ParseTo(&flags, cmd.PersistentFlags()); err != nil {
panic(err)
}
return cmd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment