Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
2a36f9df
Commit
2a36f9df
authored
Mar 08, 2011
by
Robert Hencke
Committed by
Andrew Gerrand
Mar 08, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flag: replace fail with failf
R=golang-dev, adg CC=golang-dev
https://golang.org/cl/4254061
parent
4c052844
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
flag.go
src/pkg/flag/flag.go
+8
-11
No files found.
src/pkg/flag/flag.go
View file @
2a36f9df
...
@@ -260,7 +260,9 @@ var Usage = func() {
...
@@ -260,7 +260,9 @@ var Usage = func() {
var
panicOnError
=
false
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
()
Usage
()
if
panicOnError
{
if
panicOnError
{
panic
(
"flag parse error"
)
panic
(
"flag parse error"
)
...
@@ -415,8 +417,7 @@ func (f *allFlags) parseOne() (ok bool) {
...
@@ -415,8 +417,7 @@ func (f *allFlags) parseOne() (ok bool) {
}
}
name
:=
s
[
num_minuses
:
]
name
:=
s
[
num_minuses
:
]
if
len
(
name
)
==
0
||
name
[
0
]
==
'-'
||
name
[
0
]
==
'='
{
if
len
(
name
)
==
0
||
name
[
0
]
==
'-'
||
name
[
0
]
==
'='
{
fmt
.
Fprintln
(
os
.
Stderr
,
"bad flag syntax:"
,
s
)
failf
(
"bad flag syntax: %s
\n
"
,
s
)
fail
()
}
}
// it's a flag. does it have an argument?
// it's a flag. does it have an argument?
...
@@ -434,14 +435,12 @@ func (f *allFlags) parseOne() (ok bool) {
...
@@ -434,14 +435,12 @@ func (f *allFlags) parseOne() (ok bool) {
m
:=
flags
.
formal
m
:=
flags
.
formal
flag
,
alreadythere
:=
m
[
name
]
// BUG
flag
,
alreadythere
:=
m
[
name
]
// BUG
if
!
alreadythere
{
if
!
alreadythere
{
fmt
.
Fprintf
(
os
.
Stderr
,
"flag provided but not defined: -%s
\n
"
,
name
)
failf
(
"flag provided but not defined: -%s
\n
"
,
name
)
fail
()
}
}
if
fv
,
ok
:=
flag
.
Value
.
(
*
boolValue
);
ok
{
// special case: doesn't need an arg
if
fv
,
ok
:=
flag
.
Value
.
(
*
boolValue
);
ok
{
// special case: doesn't need an arg
if
has_value
{
if
has_value
{
if
!
fv
.
Set
(
value
)
{
if
!
fv
.
Set
(
value
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"invalid boolean value %q for flag: -%s
\n
"
,
value
,
name
)
failf
(
"invalid boolean value %q for flag: -%s
\n
"
,
value
,
name
)
fail
()
}
}
}
else
{
}
else
{
fv
.
Set
(
"true"
)
fv
.
Set
(
"true"
)
...
@@ -454,13 +453,11 @@ func (f *allFlags) parseOne() (ok bool) {
...
@@ -454,13 +453,11 @@ func (f *allFlags) parseOne() (ok bool) {
value
,
f
.
args
=
f
.
args
[
0
],
f
.
args
[
1
:
]
value
,
f
.
args
=
f
.
args
[
0
],
f
.
args
[
1
:
]
}
}
if
!
has_value
{
if
!
has_value
{
fmt
.
Fprintf
(
os
.
Stderr
,
"flag needs an argument: -%s
\n
"
,
name
)
failf
(
"flag needs an argument: -%s
\n
"
,
name
)
fail
()
}
}
ok
=
flag
.
Value
.
Set
(
value
)
ok
=
flag
.
Value
.
Set
(
value
)
if
!
ok
{
if
!
ok
{
fmt
.
Fprintf
(
os
.
Stderr
,
"invalid value %q for flag: -%s
\n
"
,
value
,
name
)
failf
(
"invalid value %q for flag: -%s
\n
"
,
value
,
name
)
fail
()
}
}
}
}
flags
.
actual
[
name
]
=
flag
flags
.
actual
[
name
]
=
flag
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment