Correct all complaints from golint

* i.e.
* go get golang.org/x/lint/golint
* go list ./... | xargs golint
This commit is contained in:
Bruce Downs 2019-07-30 15:26:11 -07:00 committed by Albert Nigmatzianov
parent 9334a46bd6
commit 51f06c7dd1
6 changed files with 19 additions and 11 deletions

View file

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

View file

@ -52,7 +52,7 @@ var EnableCommandSorting = true
// if the CLI is started from explorer.exe.
// To disable the mousetrap, just set this variable to blank string ("").
// Works only on Microsoft Windows.
var MousetrapHelpText string = `This is a command line tool.
var MousetrapHelpText = `This is a command line tool.
You need to open cmd.exe and run it from there.
`
@ -61,7 +61,7 @@ You need to open cmd.exe and run it from there.
// if the CLI is started from explorer.exe. Set to 0 to wait for the return key to be pressed.
// To disable the mousetrap, just set MousetrapHelpText to blank string ("").
// Works only on Microsoft Windows.
var MousetrapDisplayDuration time.Duration = 5 * time.Second
var MousetrapDisplayDuration = 5 * time.Second
// AddTemplateFunc adds a template function that's available to Usage and Help
// template generation.

View file

@ -2,9 +2,10 @@ package cmd
import (
"fmt"
"github.com/spf13/cobra/cobra/tpl"
"os"
"text/template"
"github.com/spf13/cobra/cobra/tpl"
)
// Project contains name, license and paths to projects.
@ -18,14 +19,15 @@ 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) {
// create directory
@ -80,6 +82,7 @@ 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 {

View file

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

View file

@ -28,8 +28,8 @@ import (
flag "github.com/spf13/pflag"
)
// NotRunnable defines subcommand error
var NotRunnable = errors.New("subcommand is required")
// ErrSubCommandRequired defines subcommand error
var ErrSubCommandRequired = errors.New("subcommand is required")
// FParseErrWhitelist configures Flag parse errors to be ignored
type FParseErrWhitelist flag.ParseErrorsWhitelist
@ -232,7 +232,7 @@ func (c *Command) SetErr(newErr io.Writer) {
c.errWriter = newErr
}
// SetOut sets the source for input data
// SetIn sets the source for input data
// If newIn is nil, os.Stdin is used.
func (c *Command) SetIn(newIn io.Reader) {
c.inReader = newIn
@ -301,7 +301,7 @@ func (c *Command) ErrOrStderr() io.Writer {
return c.getErr(os.Stderr)
}
// ErrOrStderr returns output to stderr
// InOrStdin returns output to stderr
func (c *Command) InOrStdin() io.Reader {
return c.getIn(os.Stdin)
}
@ -790,7 +790,7 @@ func (c *Command) execute(a []string) (err error) {
}
if !c.Runnable() {
return NotRunnable
return ErrSubCommandRequired
}
c.preRun()
@ -927,7 +927,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
// If command wasn't runnable, show full help, but do return the error.
// This will result in apps by default returning a non-success exit code, but also gives them the option to
// handle specially.
if err == NotRunnable {
if err == ErrSubCommandRequired {
cmd.HelpFunc()(cmd, args)
return cmd, err
}
@ -947,6 +947,7 @@ 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

View file

@ -836,7 +836,7 @@ func TestHelpExecutedOnNonRunnableChild(t *testing.T) {
rootCmd.AddCommand(childCmd)
output, err := executeCommand(rootCmd, "child")
if err != NotRunnable {
if err != ErrSubCommandRequired {
t.Errorf("Expected error")
}