Adjustments per PR review feedback from @bogem

This commit is contained in:
Bruce Downs 2019-08-01 09:47:14 -07:00 committed by Albert Nigmatzianov
parent d85196337c
commit 993cc5372a
5 changed files with 1 additions and 14 deletions

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
) )
// PositionalArgs defines positional arguments callback
type PositionalArgs func(cmd *Command, args []string) error type PositionalArgs func(cmd *Command, args []string) error
// Legacy arg validation has the following behaviour: // Legacy arg validation has the following behaviour:

View File

@ -19,14 +19,12 @@ type Project struct {
AppName string AppName string
} }
// Command structure
type Command struct { type Command struct {
CmdName string CmdName string
CmdParent string CmdParent string
*Project *Project
} }
// Create project receiver
func (p *Project) Create() error { func (p *Project) Create() error {
// check if AbsolutePath exists // check if AbsolutePath exists
if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) { if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) {
@ -82,7 +80,6 @@ func (p *Project) createLicenseFile() error {
return licenseTemplate.Execute(licenseFile, data) return licenseTemplate.Execute(licenseFile, data)
} }
// Create command receiver
func (c *Command) Create() error { func (c *Command) Create() error {
cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName)) cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName))
if err != nil { if err != nil {

View File

@ -20,11 +20,7 @@ import (
) )
func main() { func main() {
if err := runMain(); err != nil { if err := cmd.Execute(); err != nil {
os.Exit(1) os.Exit(1)
} }
} }
func runMain() error {
return cmd.Execute()
}

View File

@ -1,6 +1,5 @@
package tpl package tpl
// MainTemplate defines main template string
func MainTemplate() []byte { func MainTemplate() []byte {
return []byte(`/* return []byte(`/*
{{ .Copyright }} {{ .Copyright }}
@ -16,7 +15,6 @@ func main() {
`) `)
} }
// RootTemplate defines root template string
func RootTemplate() []byte { func RootTemplate() []byte {
return []byte(`/* return []byte(`/*
{{ .Copyright }} {{ .Copyright }}
@ -110,7 +108,6 @@ func initConfig() {
`) `)
} }
// AddCommandTemplate defines add command template string
func AddCommandTemplate() []byte { func AddCommandTemplate() []byte {
return []byte(`/* return []byte(`/*
{{ .Project.Copyright }} {{ .Project.Copyright }}

View File

@ -28,7 +28,6 @@ import (
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
) )
// ErrSubCommandRequired defines subcommand error
var ErrSubCommandRequired = errors.New("subcommand is required") var ErrSubCommandRequired = errors.New("subcommand is required")
// FParseErrWhitelist configures Flag parse errors to be ignored // FParseErrWhitelist configures Flag parse errors to be ignored
@ -947,7 +946,6 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
return cmd, err return cmd, err
} }
// ValidateArgs validates arguments
func (c *Command) ValidateArgs(args []string) error { func (c *Command) ValidateArgs(args []string) error {
if c.Args == nil { if c.Args == nil {
return nil return nil