forked from mirror/cobra
Adjustments per PR review feedback from @bogem
This commit is contained in:
parent
d85196337c
commit
993cc5372a
1
args.go
1
args.go
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// PositionalArgs defines positional arguments callback
|
||||
type PositionalArgs func(cmd *Command, args []string) error
|
||||
|
||||
// Legacy arg validation has the following behaviour:
|
||||
|
|
|
@ -19,14 +19,12 @@ type Project struct {
|
|||
AppName string
|
||||
}
|
||||
|
||||
// Command structure
|
||||
type Command struct {
|
||||
CmdName string
|
||||
CmdParent string
|
||||
*Project
|
||||
}
|
||||
|
||||
// Create project receiver
|
||||
func (p *Project) Create() error {
|
||||
// check if AbsolutePath exists
|
||||
if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) {
|
||||
|
@ -82,7 +80,6 @@ func (p *Project) createLicenseFile() error {
|
|||
return licenseTemplate.Execute(licenseFile, data)
|
||||
}
|
||||
|
||||
// Create command receiver
|
||||
func (c *Command) Create() error {
|
||||
cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName))
|
||||
if err != nil {
|
||||
|
|
|
@ -20,11 +20,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
if err := runMain(); err != nil {
|
||||
if err := cmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func runMain() error {
|
||||
return cmd.Execute()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package tpl
|
||||
|
||||
// MainTemplate defines main template string
|
||||
func MainTemplate() []byte {
|
||||
return []byte(`/*
|
||||
{{ .Copyright }}
|
||||
|
@ -16,7 +15,6 @@ func main() {
|
|||
`)
|
||||
}
|
||||
|
||||
// RootTemplate defines root template string
|
||||
func RootTemplate() []byte {
|
||||
return []byte(`/*
|
||||
{{ .Copyright }}
|
||||
|
@ -110,7 +108,6 @@ func initConfig() {
|
|||
`)
|
||||
}
|
||||
|
||||
// AddCommandTemplate defines add command template string
|
||||
func AddCommandTemplate() []byte {
|
||||
return []byte(`/*
|
||||
{{ .Project.Copyright }}
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// ErrSubCommandRequired defines subcommand error
|
||||
var ErrSubCommandRequired = errors.New("subcommand is required")
|
||||
|
||||
// FParseErrWhitelist configures Flag parse errors to be ignored
|
||||
|
@ -947,7 +946,6 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
|||
return cmd, err
|
||||
}
|
||||
|
||||
// ValidateArgs validates arguments
|
||||
func (c *Command) ValidateArgs(args []string) error {
|
||||
if c.Args == nil {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue