Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(646)

Issue 4254061: code review 4254061: flag: replace fail with failf (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 2 months ago by rh
Modified:
14 years, 2 months ago
Reviewers:
CC:
golang-dev, adg
Visibility:
Public.

Description

flag: replace fail with failf

Patch Set 1 #

Patch Set 2 : diff -r 42ac251c14b0 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 42ac251c14b0 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 42ac251c14b0 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+8 lines, -11 lines) Patch
M src/pkg/flag/flag.go View 1 2 4 chunks +8 lines, -11 lines 0 comments Download

Messages

Total messages: 3
rh
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
14 years, 2 months ago (2011-03-08 04:22:09 UTC) #1
adg
*** Submitted as http://code.google.com/p/go/source/detail?r=843ca48aceae *** flag: replace fail with failf R=golang-dev, adg CC=golang-dev http://codereview.appspot.com/4254061 Committer: ...
14 years, 2 months ago (2011-03-08 04:41:45 UTC) #2
adg
14 years, 2 months ago (2011-03-08 04:49:30 UTC) #3
LGTM

On 8 March 2011 15:22,  <robert.hencke@gmail.com> wrote:
> Reviewers: golang-dev_googlegroups.com,
>
> Message:
> Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),
>
> I'd like you to review this change to
> https://go.googlecode.com/hg/
>
>
> Description:
> flag: replace fail with failf
>
> Please review this at http://codereview.appspot.com/4254061/
>
> Affected files:
>  M src/pkg/flag/flag.go
>
>
> Index: src/pkg/flag/flag.go
> ===================================================================
> --- a/src/pkg/flag/flag.go
> +++ b/src/pkg/flag/flag.go
> @@ -260,7 +260,9 @@
>
>  var panicOnError = false
>
> -func fail() {
> +// failf prints to standard output a formatted error and Usage, and then
> exits the program.
> +func failf(format string, a ...interface{}) {
> +       fmt.Fprintf(os.Stderr, format, a...)
>        Usage()
>        if panicOnError {
>                panic("flag parse error")
> @@ -415,8 +417,7 @@
>        }
>        name := s[num_minuses:]
>        if len(name) == 0 || name[0] == '-' || name[0] == '=' {
> -               fmt.Fprintln(os.Stderr, "bad flag syntax:", s)
> -               fail()
> +               failf("bad flag syntax: %s\n", s)
>        }
>
>        // it's a flag. does it have an argument?
> @@ -434,14 +435,12 @@
>        m := flags.formal
>        flag, alreadythere := m[name] // BUG
>        if !alreadythere {
> -               fmt.Fprintf(os.Stderr, "flag provided but not defined:
> -%s\n", name)
> -               fail()
> +               failf("flag provided but not defined: -%s\n", name)
>        }
>        if fv, ok := flag.Value.(*boolValue); ok { // special case: doesn't
> need an arg
>                if has_value {
>                        if !fv.Set(value) {
> -                               fmt.Fprintf(os.Stderr, "invalid boolean
> value %q for flag: -%s\n", value, name)
> -                               fail()
> +                               failf("invalid boolean value %q for flag:
> -%s\n", value, name)
>                        }
>                } else {
>                        fv.Set("true")
> @@ -454,13 +453,11 @@
>                        value, f.args = f.args[0], f.args[1:]
>                }
>                if !has_value {
> -                       fmt.Fprintf(os.Stderr, "flag needs an argument:
> -%s\n", name)
> -                       fail()
> +                       failf("flag needs an argument: -%s\n", name)
>                }
>                ok = flag.Value.Set(value)
>                if !ok {
> -                       fmt.Fprintf(os.Stderr, "invalid value %q for flag:
> -%s\n", value, name)
> -                       fail()
> +                       failf("invalid value %q for flag: -%s\n", value,
> name)
>                }
>        }
>        flags.actual[name] = flag
>
>
>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b