Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contrib
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
contrib
Commits
1967183f
Commit
1967183f
authored
6 years ago
by
Miguel Montes
Browse files
Options
Downloads
Patches
Plain Diff
Cambios en el manejo de errores
Cambios en el procesamiento de la línea de comandos
parent
58ae5c27
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bfa_client/src/client/bfa_client.go
+8
-11
8 additions, 11 deletions
bfa_client/src/client/bfa_client.go
bfa_client/src/util/util.go
+21
-6
21 additions, 6 deletions
bfa_client/src/util/util.go
with
29 additions
and
17 deletions
bfa_client/src/client/bfa_client.go
+
8
−
11
View file @
1967183f
...
...
@@ -28,7 +28,6 @@ var (
json
bool
help
bool
flags
=
flag
.
NewFlagSet
(
""
,
flag
.
ExitOnError
)
command
string
description
string
otherArgs
string
)
...
...
@@ -61,7 +60,8 @@ func updateURL(url string) (updated string) {
}
func
usage
(
errorCode
int
)
{
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
"Uso: %v %v [opciones] %v
\n
%v
\n
"
,
os
.
Args
[
0
],
command
,
otherArgs
,
description
)
util
.
Require
(
len
(
os
.
Args
)
>
1
,
"not enough arguments"
)
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
"Uso: %v %v [opciones] %v
\n
%v
\n
"
,
os
.
Args
[
0
],
os
.
Args
[
1
],
otherArgs
,
description
)
flags
.
PrintDefaults
()
os
.
Exit
(
errorCode
)
}
...
...
@@ -441,9 +441,10 @@ func main() {
"snapshot"
:
snapshot
,
}
validCommands
[]
string
command
func
()
)
for
c
omman
d
:=
range
commands
{
validCommands
=
append
(
validCommands
,
c
omman
d
)
for
c
m
d
:=
range
commands
{
validCommands
=
append
(
validCommands
,
c
m
d
)
}
sort
.
Strings
(
validCommands
)
//defer func() {
...
...
@@ -452,12 +453,8 @@ func main() {
// }
//}()
if
len
(
os
.
Args
)
>
1
{
command
=
os
.
Args
[
1
]
command
=
commands
[
os
.
Args
[
1
]
]
}
if
commands
[
command
]
==
nil
{
log
.
Printf
(
"Uso: %v <%v> [opciones]
\n
"
,
path
.
Base
(
os
.
Args
[
0
]),
strings
.
Join
(
validCommands
,
"|"
))
log
.
Printf
(
"Para ayuda: %v <command> -h
\n
"
,
path
.
Base
(
os
.
Args
[
0
]))
os
.
Exit
(
1
)
}
commands
[
command
]()
util
.
Ensure
(
command
!=
nil
,
"Uso: %v <%v> [opciones]
\n
Para ayuda: %v <command> -h
\n
"
,
path
.
Base
(
os
.
Args
[
0
]),
strings
.
Join
(
validCommands
,
"|"
),
path
.
Base
(
os
.
Args
[
0
]))
command
()
}
This diff is collapsed.
Click to expand it.
bfa_client/src/util/util.go
+
21
−
6
View file @
1967183f
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"log"
"os"
"runtime"
"strconv"
)
...
...
@@ -19,12 +20,21 @@ func Contains(slice []string, s string) bool {
return
false
}
func
Check
(
err
error
)
{
if
err
!=
nil
{
panic
(
err
.
Error
())
func
Error
(
format
string
,
args
...
interface
{})
{
_
,
_
=
fmt
.
Fprintf
(
os
.
Stderr
,
format
,
args
...
)
os
.
Exit
(
1
)
}
func
Ensure
(
condition
bool
,
format
string
,
args
...
interface
{})
{
if
!
condition
{
Error
(
format
,
args
...
)
}
}
func
Check
(
err
error
)
{
Ensure
(
err
==
nil
,
"%v
\n
"
,
err
)
}
func
BytesToHex
(
b
[]
byte
)
string
{
return
fmt
.
Sprintf
(
"0x%02x"
,
b
)
}
...
...
@@ -33,6 +43,13 @@ func Int64ToHex(n int64) string {
return
"0x"
+
strconv
.
FormatInt
(
n
,
16
)
}
func
Require
(
condition
bool
,
msg
string
)
{
if
!
condition
{
ptr
,
_
,
_
,
_
:=
runtime
.
Caller
(
1
)
log
.
Panicf
(
"%v in %v"
,
msg
,
runtime
.
FuncForPC
(
ptr
)
.
Name
())
}
}
func
PrintDebug
(
prefix
,
suffix
string
)
{
ptr
,
_
,
_
,
_
:=
runtime
.
Caller
(
1
)
fmt
.
Printf
(
"%v: %v%v
\n
"
,
prefix
,
runtime
.
FuncForPC
(
ptr
)
.
Name
(),
suffix
)
...
...
@@ -65,7 +82,5 @@ func IsAddress(address string) bool {
}
func
DieIf
(
cond
bool
,
format
string
,
args
...
interface
{})
{
if
cond
{
log
.
Fatalf
(
format
,
args
...
)
}
Ensure
(
!
cond
,
format
,
args
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment