2016-06-01 05:19:13 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FlagErrorFunc prints an error messages which matches the format of the
|
|
|
|
// docker/docker/cli error messages
|
|
|
|
func FlagErrorFunc(cmd *cobra.Command, err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
usage := ""
|
|
|
|
if cmd.HasSubCommands() {
|
|
|
|
usage = "\n\n" + cmd.UsageString()
|
|
|
|
}
|
2016-09-21 14:43:13 +00:00
|
|
|
return StatusError{
|
|
|
|
Status: fmt.Sprintf("%s\nSee '%s --help'.%s", err, cmd.CommandPath(), usage),
|
|
|
|
StatusCode: 125,
|
|
|
|
}
|
2016-06-01 05:19:13 +00:00
|
|
|
}
|