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

View file

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

View file

@ -47,6 +47,15 @@ var EnablePrefixMatching = false
// To disable sorting, set it to false.
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
// template generation.
func AddTemplateFunc(name string, tmplFunc interface{}) {

View file

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

View file

@ -767,17 +767,16 @@ func (c *Command) InitDefaultHelpFlag() {
// 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.
func (c *Command) InitDefaultHelpCmd() {
if c.helpCommand != nil || !c.HasSubCommands() {
if !c.HasSubCommands() {
return
}
if c.helpCommand == nil {
c.helpCommand = &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.`,
PersistentPreRun: func(cmd *Command, args []string) {},
PersistentPostRun: func(cmd *Command, args []string) {},
Simply type ` + c.Name() + ` help [path to command] for full details.`,
Run: func(c *Command, args []string) {
cmd, _, e := c.Root().Find(args)
@ -790,6 +789,7 @@ func (c *Command) InitDefaultHelpCmd() {
}
},
}
}
c.RemoveCommand(c.helpCommand)
c.AddCommand(c.helpCommand)
}

View file

@ -120,7 +120,6 @@ func TestStripFlags(t *testing.T) {
}
func TestDisableFlagParsing(t *testing.T) {
as := []string{"-v", "-race", "-file", "foo.go"}
targs := []string{}
cmdPrint := &Command{
DisableFlagParsing: true,
@ -128,14 +127,14 @@ func TestDisableFlagParsing(t *testing.T) {
targs = args
},
}
osargs := []string{"cmd"}
os.Args = append(osargs, as...)
args := []string{"cmd", "-v", "-race", "-file", "foo.go"}
cmdPrint.SetArgs(args)
err := cmdPrint.Execute()
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(as, targs) {
t.Errorf("expected: %v, got: %v", as, targs)
if !reflect.DeepEqual(args, 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") {
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
// 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) {
if mousetrap.StartedByExplorer() {
if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {
c.Print(MousetrapHelpText)
time.Sleep(5 * time.Second)
os.Exit(1)