Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (46 sloc) 876 Bytes
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/pflag"
"github.com/x-mod/errors"
)
//default root command
var rootCmd *Command
func _program() string {
return filepath.Base(os.Args[0])
}
//Add for default root command
func Add(opts ...CommandOpt) *Command {
c := newCommand(opts...)
c.build()
return c
}
//PersistentFlags
func PersistentFlags() *pflag.FlagSet {
return rootCmd.PersistentFlags()
}
//Flags
func Flags() *pflag.FlagSet {
return rootCmd.Flags()
}
//Version root command
func Version(v string) {
rootCmd.Version = v
}
//Execute for default root command
func Execute() {
Exit(rootCmd.Execute())
}
//Exit with error code
func Exit(err error) {
if err != nil {
fmt.Println("failed: ", err)
os.Exit(int(errors.ValueFrom(err)))
}
}
func init() {
rootCmd = newCommand(Name(_program()))
rootCmd.TraverseChildren = true
}
You can’t perform that action at this time.