lbcctl: support --timed, --quiet options
This commit is contained in:
parent
987a533423
commit
cbc4d489e8
2 changed files with 18 additions and 3 deletions
|
@ -111,6 +111,8 @@ type config struct {
|
||||||
SigNet bool `long:"signet" description:"Connect to signet (default RPC server: localhost:49245)"`
|
SigNet bool `long:"signet" description:"Connect to signet (default RPC server: localhost:49245)"`
|
||||||
Wallet bool `long:"wallet" description:"Connect to wallet RPC server instead (default: localhost:9244, testnet: localhost:19244, regtest: localhost:29244)"`
|
Wallet bool `long:"wallet" description:"Connect to wallet RPC server instead (default: localhost:9244, testnet: localhost:19244, regtest: localhost:29244)"`
|
||||||
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
|
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
|
||||||
|
Timed bool `short:"t" long:"timed" description:"Display RPC response time"`
|
||||||
|
Quiet bool `short:"q" long:"quiet" description:"Do not output results to stdout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeAddress returns addr with the passed default port appended if
|
// normalizeAddress returns addr with the passed default port appended if
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/lbryio/lbcd/btcjson"
|
"github.com/lbryio/lbcd/btcjson"
|
||||||
)
|
)
|
||||||
|
@ -133,6 +134,8 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
started := time.Now()
|
||||||
|
|
||||||
// Send the JSON-RPC request to the server using the user-specified
|
// Send the JSON-RPC request to the server using the user-specified
|
||||||
// connection configuration.
|
// connection configuration.
|
||||||
result, err := sendPostRequest(marshalledJSON, cfg)
|
result, err := sendPostRequest(marshalledJSON, cfg)
|
||||||
|
@ -141,6 +144,16 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Timed {
|
||||||
|
elapsed := time.Since(started)
|
||||||
|
defer fmt.Fprintf(os.Stderr, "%s\n", elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
var output io.Writer = os.Stdout
|
||||||
|
if cfg.Quiet {
|
||||||
|
output = io.Discard
|
||||||
|
}
|
||||||
|
|
||||||
// Choose how to display the result based on its type.
|
// Choose how to display the result based on its type.
|
||||||
strResult := string(result)
|
strResult := string(result)
|
||||||
if strings.HasPrefix(strResult, "{") || strings.HasPrefix(strResult, "[") {
|
if strings.HasPrefix(strResult, "{") || strings.HasPrefix(strResult, "[") {
|
||||||
|
@ -150,7 +163,7 @@ func main() {
|
||||||
err)
|
err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println(dst.String())
|
fmt.Fprintln(output, dst.String())
|
||||||
|
|
||||||
} else if strings.HasPrefix(strResult, `"`) {
|
} else if strings.HasPrefix(strResult, `"`) {
|
||||||
var str string
|
var str string
|
||||||
|
@ -159,9 +172,9 @@ func main() {
|
||||||
err)
|
err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
fmt.Println(str)
|
fmt.Fprintln(output, str)
|
||||||
|
|
||||||
} else if strResult != "null" {
|
} else if strResult != "null" {
|
||||||
fmt.Println(strResult)
|
fmt.Fprintln(output, strResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue