Update dependencies

This commit is contained in:
Zlatko Čalušić 2017-07-19 22:18:06 +02:00
parent 0e5f662fed
commit cae51e1478
7 changed files with 87 additions and 47 deletions

4
Gopkg.lock generated
View file

@ -4,7 +4,7 @@
[[projects]] [[projects]]
name = "github.com/gorilla/handlers" name = "github.com/gorilla/handlers"
packages = ["."] packages = ["."]
revision = "a4d79d4487c2430a17d9dc8a1f74d1a6ed6908ca" revision = "a4043c62cc2329bacda331d33fc908ab11ef0ec3"
source = "https://github.com/gorilla/handlers" source = "https://github.com/gorilla/handlers"
version = "v1.2.1" version = "v1.2.1"
@ -18,7 +18,7 @@
branch = "master" branch = "master"
name = "github.com/spf13/cobra" name = "github.com/spf13/cobra"
packages = ["."] packages = ["."]
revision = "4d647c8944eb42504a714e57e97f244ed6344722" revision = "715f41bd7a70b5111f898b71ab484da52ee6266d"
[[projects]] [[projects]]
branch = "master" branch = "master"

View file

@ -7,7 +7,6 @@ matrix:
- go: 1.5 - go: 1.5
- go: 1.6 - go: 1.6
- go: 1.7 - go: 1.7
- go: 1.8
- go: tip - go: tip
allow_failures: allow_failures:
- go: tip - go: tip
@ -17,4 +16,3 @@ script:
- diff -u <(echo -n) <(gofmt -d .) - diff -u <(echo -n) <(gofmt -d .)
- go vet $(go list ./... | grep -v /vendor/) - go vet $(go list ./... | grep -v /vendor/)
- go test -v -race ./... - go test -v -race ./...

View file

@ -47,6 +47,15 @@ var EnablePrefixMatching = false
// To disable sorting, set it to false. // To disable sorting, set it to false.
var EnableCommandSorting = true var EnableCommandSorting = true
// MousetrapHelpText enables an information splash screen on Windows
// 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.
You need to open cmd.exe and run it from there.
`
// AddTemplateFunc adds a template function that's available to Usage and Help // AddTemplateFunc adds a template function that's available to Usage and Help
// template generation. // template generation.
func AddTemplateFunc(name string, tmplFunc interface{}) { func AddTemplateFunc(name string, tmplFunc interface{}) {

View file

@ -45,24 +45,34 @@ func er(msg interface{}) {
} }
// isEmpty checks if a given path is empty. // isEmpty checks if a given path is empty.
// Hidden files in path are ignored.
func isEmpty(path string) bool { func isEmpty(path string) bool {
fi, err := os.Stat(path) fi, err := os.Stat(path)
if err != nil { if err != nil {
er(err) er(err)
} }
if fi.IsDir() {
f, err := os.Open(path) if !fi.IsDir() {
if err != nil { return fi.Size() == 0
er(err)
}
defer f.Close()
dirs, err := f.Readdirnames(1)
if err != nil && err != io.EOF {
er(err)
}
return len(dirs) == 0
} }
return fi.Size() == 0
f, err := os.Open(path)
if err != nil {
er(err)
}
defer f.Close()
names, err := f.Readdirnames(-1)
if err != nil && err != io.EOF {
er(err)
}
for _, name := range names {
if len(name) > 0 && name[0] != '.' {
return false
}
}
return true
} }
// exists checks if a file or directory exists. // exists checks if a file or directory exists.

View file

@ -767,28 +767,28 @@ func (c *Command) InitDefaultHelpFlag() {
// It is called automatically by executing the c or by calling help and usage. // It is called automatically by executing the c or by calling help and usage.
// If c already has help command or c has no subcommands, it will do nothing. // If c already has help command or c has no subcommands, it will do nothing.
func (c *Command) InitDefaultHelpCmd() { func (c *Command) InitDefaultHelpCmd() {
if c.helpCommand != nil || !c.HasSubCommands() { if !c.HasSubCommands() {
return return
} }
c.helpCommand = &Command{ if c.helpCommand == nil {
Use: "help [command]", c.helpCommand = &Command{
Short: "Help about any command", Use: "help [command]",
Long: `Help provides help for any command in the application. Short: "Help about any command",
Simply type ` + c.Name() + ` help [path to command] for full details.`, Long: `Help provides help for any command in the application.
PersistentPreRun: func(cmd *Command, args []string) {}, Simply type ` + c.Name() + ` help [path to command] for full details.`,
PersistentPostRun: func(cmd *Command, args []string) {},
Run: func(c *Command, args []string) { Run: func(c *Command, args []string) {
cmd, _, e := c.Root().Find(args) cmd, _, e := c.Root().Find(args)
if cmd == nil || e != nil { if cmd == nil || e != nil {
c.Printf("Unknown help topic %#q\n", args) c.Printf("Unknown help topic %#q\n", args)
c.Root().Usage() c.Root().Usage()
} else { } else {
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
cmd.Help() cmd.Help()
} }
}, },
}
} }
c.RemoveCommand(c.helpCommand) c.RemoveCommand(c.helpCommand)
c.AddCommand(c.helpCommand) c.AddCommand(c.helpCommand)

View file

@ -120,7 +120,6 @@ func TestStripFlags(t *testing.T) {
} }
func TestDisableFlagParsing(t *testing.T) { func TestDisableFlagParsing(t *testing.T) {
as := []string{"-v", "-race", "-file", "foo.go"}
targs := []string{} targs := []string{}
cmdPrint := &Command{ cmdPrint := &Command{
DisableFlagParsing: true, DisableFlagParsing: true,
@ -128,14 +127,14 @@ func TestDisableFlagParsing(t *testing.T) {
targs = args targs = args
}, },
} }
osargs := []string{"cmd"} args := []string{"cmd", "-v", "-race", "-file", "foo.go"}
os.Args = append(osargs, as...) cmdPrint.SetArgs(args)
err := cmdPrint.Execute() err := cmdPrint.Execute()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if !reflect.DeepEqual(as, targs) { if !reflect.DeepEqual(args, targs) {
t.Errorf("expected: %v, got: %v", as, targs) t.Errorf("expected: %v, got: %v", args, targs)
} }
} }
@ -316,5 +315,35 @@ func TestUseDeprecatedFlags(t *testing.T) {
if !strings.Contains(output.String(), "This flag is deprecated") { if !strings.Contains(output.String(), "This flag is deprecated") {
t.Errorf("Expected to contain deprecated message, but got %q", output.String()) t.Errorf("Expected to contain deprecated message, but got %q", output.String())
} }
}
// TestSetHelpCommand checks, if SetHelpCommand works correctly.
func TestSetHelpCommand(t *testing.T) {
c := &Command{Use: "c", Run: func(*Command, []string) {}}
output := new(bytes.Buffer)
c.SetOutput(output)
c.SetArgs([]string{"help"})
// Help will not be shown, if c has no subcommands.
c.AddCommand(&Command{
Use: "empty",
Run: func(cmd *Command, args []string) {},
})
correctMessage := "WORKS"
c.SetHelpCommand(&Command{
Use: "help [command]",
Short: "Help about any command",
Long: `Help provides help for any command in the application.
Simply type ` + c.Name() + ` help [path to command] for full details.`,
Run: func(c *Command, args []string) { c.Print(correctMessage) },
})
if err := c.Execute(); err != nil {
t.Error("Unexpected error:", err)
}
if output.String() != correctMessage {
t.Errorf("Expected to contain %q message, but got %q", correctMessage, output.String())
}
} }

View file

@ -11,14 +11,8 @@ import (
var preExecHookFn = preExecHook var preExecHookFn = preExecHook
// enables an information splash screen on Windows if the CLI is started from explorer.exe.
var MousetrapHelpText string = `This is a command line tool
You need to open cmd.exe and run it from there.
`
func preExecHook(c *Command) { func preExecHook(c *Command) {
if mousetrap.StartedByExplorer() { if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {
c.Print(MousetrapHelpText) c.Print(MousetrapHelpText)
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
os.Exit(1) os.Exit(1)