diff options
| author | Joseph Richey <joerichey94@gmail.com> | 2017-10-16 10:50:53 -0700 |
|---|---|---|
| committer | Joseph Richey <joerichey94@gmail.com> | 2017-10-19 02:22:25 -0700 |
| commit | b5cc60b2b974645f0d09721c292cd243d049cbcf (patch) | |
| tree | fbc44d87ba8dd83e2238ff8e217ea560f56b3091 /cmd/fscrypt/errors.go | |
| parent | b4299090c3e503ba0c49a6086b1a46c218ca45f4 (diff) | |
Refactor almost complete
Diffstat (limited to 'cmd/fscrypt/errors.go')
| -rw-r--r-- | cmd/fscrypt/errors.go | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/cmd/fscrypt/errors.go b/cmd/fscrypt/errors.go index 81a6798..4ce6133 100644 --- a/cmd/fscrypt/errors.go +++ b/cmd/fscrypt/errors.go @@ -22,10 +22,7 @@ package main import ( - "bytes" "fmt" - "os" - "path/filepath" "unicode/utf8" "github.com/pkg/errors" @@ -165,40 +162,6 @@ func newExitError(c *cli.Context, err error) error { return cli.NewExitError(message, failureExitCode) } -// usageError implements cli.ExitCoder to will print the usage and the return a -// non-zero value. This error should be used when a command is used incorrectly. -type usageError struct { - c *cli.Context - message string -} - -func (u *usageError) Error() string { - return fmt.Sprintf("%s: %s", getFullName(u.c), u.message) -} - -// We get the help to print after the error by having it run right before the -// application exits. This is very nasty, but there isn't a better way to do it -// with the constraints of urfave/cli. -func (u *usageError) ExitCode() int { - // Redirect help output to a buffer, so we can customize it. - buf := new(bytes.Buffer) - oldWriter := u.c.App.Writer - u.c.App.Writer = buf - - // Get the appropriate help - if getFullName(u.c) == filepath.Base(os.Args[0]) { - cli.ShowAppHelp(u.c) - } else { - cli.ShowCommandHelp(u.c, u.c.Command.Name) - } - - // Remove first line from help and print it out - buf.ReadBytes('\n') - buf.WriteTo(oldWriter) - u.c.App.Writer = oldWriter - return failureExitCode -} - // expectedArgsErr creates a usage error for the incorrect number of arguments // being specified. atMost should be true only if any number of arguments from 0 // to expectedArgs would be acceptable. |