~jameinel/juju-core/api-facade-registry

« back to all changes in this revision

Viewing changes to cmd/cmd.go

  • Committer: John Arbash Meinel
  • Date: 2014-05-14 12:29:15 UTC
  • mfrom: (2715.2.15 juju-core)
  • Revision ID: john@arbash-meinel.com-20140514122915-lf70e9bkkxx9m11q
Merge trunk r2730

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
        return buf.Bytes()
211
211
}
212
212
 
213
 
// Errors from commands can be either ErrHelp, which means "show the help" or
214
 
// some other error related to needed flags missing, or needed positional args
215
 
// missing, in which case we should print the error and return a non-zero
216
 
// return code.
217
 
func handleCommandError(c Command, ctx *Context, err error, f *gnuflag.FlagSet) (int, bool) {
218
 
        if err == gnuflag.ErrHelp {
 
213
// Errors from commands can be ErrSilent (don't print an error message),
 
214
// ErrHelp (show the help) or some other error related to needed flags
 
215
// missing, or needed positional args missing, in which case we should
 
216
// print the error and return a non-zero return code.
 
217
func handleCommandError(c Command, ctx *Context, err error, f *gnuflag.FlagSet) (rc int, done bool) {
 
218
        switch err {
 
219
        case nil:
 
220
                return 0, false
 
221
        case gnuflag.ErrHelp:
219
222
                ctx.Stdout.Write(c.Info().Help(f))
220
223
                return 0, true
221
 
        }
222
 
        if err != nil {
 
224
        case ErrSilent:
 
225
                return 2, true
 
226
        default:
223
227
                fmt.Fprintf(ctx.Stderr, "error: %v\n", err)
224
228
                return 2, true
225
229
        }
226
 
        return 0, false
227
230
}
228
231
 
229
232
// Main runs the given Command in the supplied Context with the given