Skip to content

Commit

Permalink
Add silent mode -s (#172)
Browse files Browse the repository at this point in the history
Add silent mode -s
  • Loading branch information
GollyTicker committed Feb 26, 2024
2 parents e0fdf82 + 9646d2e commit 6b43a63
Show file tree
Hide file tree
Showing 68 changed files with 171 additions and 37 deletions.
3 changes: 2 additions & 1 deletion EXAMPLES.md
Expand Up @@ -199,6 +199,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -435,7 +436,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:21:38 GMT
Date: Tue, 20 Feb 2024 23:06:35 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 35
Expand Down
1 change: 1 addition & 0 deletions doc/generated.usage.txt
Expand Up @@ -40,6 +40,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
10 changes: 10 additions & 0 deletions src/flags.go
Expand Up @@ -124,6 +124,10 @@ func intialiseFlags() {
flags.BoolVarP(&CurrentConfig.ShowOutputOnly, "show-output-only", "q", false,
"Suppresses all output except response Protobuf as text. "+
"Overrides and deactivates -v and -D. Errors are still printed to stderr.")

flags.BoolVarP(&CurrentConfig.SilentMode, "silent", "s", false,
"Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. "+
"Errors are still printed to stderr.")
}

func propagateFlags() {
Expand All @@ -137,6 +141,12 @@ func propagateFlags() {
CurrentConfig.DisplayBinaryAndHttp = false
}

if CurrentConfig.SilentMode {
CurrentConfig.Verbose = false
CurrentConfig.DisplayBinaryAndHttp = false
CurrentConfig.ShowOutputOnly = false
}

if CurrentConfig.ResponseType == "" && !CurrentConfig.DecodeRawResponse {
CurrentConfig.DecodeRawResponse = true
if CurrentConfig.Verbose {
Expand Down
2 changes: 1 addition & 1 deletion src/httpRequest.go
Expand Up @@ -117,7 +117,7 @@ func invokeCurlRequest(requestBinary []byte, curlPath string) ([]byte, string) {

err = curlCmd.Run()

if !CurrentConfig.ShowOutputOnly && curlStdOut.Len() != 0 {
if !CurrentConfig.ShowOutputOnly && !CurrentConfig.SilentMode && curlStdOut.Len() != 0 {
fmt.Printf("%s CURL Output %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, curlStdOut.String())
}

Expand Down
13 changes: 8 additions & 5 deletions src/protocurl.go
Expand Up @@ -30,6 +30,7 @@ type Config struct {
AdditionalCurlArgs string
Verbose bool
ShowOutputOnly bool
SilentMode bool
ForceNoCurl bool
ForceCurl bool
GlobalProtoc bool
Expand Down Expand Up @@ -112,13 +113,13 @@ func encodeToBinary(requestType string, text string, registry *protoregistry.Fil
registry,
)

if !CurrentConfig.ShowOutputOnly {
if !CurrentConfig.ShowOutputOnly && !CurrentConfig.SilentMode {
fmt.Printf("%s %s Request %s %s %s\n%s\n",
VISUAL_SEPARATOR, CurrentConfig.Method, displayIn(CurrentConfig.InTextType), VISUAL_SEPARATOR,
SEND, reconstructedRequestText)
}

if !CurrentConfig.ShowOutputOnly && CurrentConfig.DisplayBinaryAndHttp {
if CurrentConfig.DisplayBinaryAndHttp && !CurrentConfig.SilentMode {
fmt.Printf("%s %s Request Binary %s %s\n%s", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, SEND, hex.Dump(requestBinary))
}

Expand Down Expand Up @@ -150,7 +151,7 @@ func invokeHttpRequestBasedOnConfig(requestBinary []byte) ([]byte, string) {
}

func decodeResponse(responseBinary []byte, responseHeaders string, registry *protoregistry.Files) {
if !CurrentConfig.ShowOutputOnly && CurrentConfig.DisplayBinaryAndHttp {
if CurrentConfig.DisplayBinaryAndHttp && !CurrentConfig.SilentMode {
fmt.Printf("%s %s Response Headers %s %s\n%s\n", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, RECV, responseHeaders)

fmt.Printf("%s %s Response Binary %s %s\n%s", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, RECV, hex.Dump(responseBinary))
Expand All @@ -160,11 +161,13 @@ func decodeResponse(responseBinary []byte, responseHeaders string, registry *pro

responseText, _ := protoBinaryToMsgAndText(responseMessageType, responseBinary, CurrentConfig.OutTextType, registry)

if !CurrentConfig.ShowOutputOnly {
if !CurrentConfig.ShowOutputOnly && !CurrentConfig.SilentMode {
fmt.Printf("%s %s Response %s %s %s\n",
VISUAL_SEPARATOR, CurrentConfig.Method, displayOut(CurrentConfig.OutTextType), VISUAL_SEPARATOR, RECV)
}
fmt.Printf("%s\n", responseText)
if !CurrentConfig.SilentMode {
fmt.Printf("%s\n", responseText)
}
}

func properResponseTypeIfProvidedOrEmptyType() string {
Expand Down
5 changes: 3 additions & 2 deletions test/results/additional-curl-args-verbose--X_GET-expected.txt
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "-v --ipv4 -A my-user-agent",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": true,
"GlobalProtoc": false,
Expand Down Expand Up @@ -279,7 +280,7 @@ Total curl args:
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/x-protobuf
< Date: Thu, 05 Oct 2023 09:18:02 GMT
< Date: Tue, 20 Feb 2024 22:11:16 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Content-Length: 65
Expand All @@ -290,7 +291,7 @@ Total curl args:
=========================== GET Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:18:02 GMT
Date: Tue, 20 Feb 2024 22:11:16 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 65
Expand Down
5 changes: 3 additions & 2 deletions test/results/additional-curl-args-verbose-expected.txt
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "-v --ipv4 -A my-user-agent",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": true,
"GlobalProtoc": false,
Expand Down Expand Up @@ -279,7 +280,7 @@ Total curl args:
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/x-protobuf
< Date: Thu, 05 Oct 2023 09:18:01 GMT
< Date: Tue, 20 Feb 2024 22:11:16 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Content-Length: 65
Expand All @@ -290,7 +291,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:18:01 GMT
Date: Tue, 20 Feb 2024 22:11:16 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 65
Expand Down
3 changes: 2 additions & 1 deletion test/results/echo-empty--X_GET_-v-expected.txt
Expand Up @@ -23,6 +23,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -253,7 +254,7 @@ Total curl args:
=========================== GET Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:18:15 GMT
Date: Tue, 20 Feb 2024 22:11:32 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 0
Expand Down
3 changes: 2 additions & 1 deletion test/results/echo-empty--X_HEAD_-v-expected.txt
Expand Up @@ -23,6 +23,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -253,7 +254,7 @@ Total curl args:
=========================== HEAD Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:18:21 GMT
Date: Tue, 20 Feb 2024 22:11:38 GMT
Connection: keep-alive
Keep-Alive: timeout=5
=========================== HEAD Response Binary =========================== <<<
Expand Down
4 changes: 4 additions & 0 deletions test/results/failure-simple-quiet--D-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-quiet--v-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent--D-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent--X_GET-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent--q-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent--v-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
4 changes: 4 additions & 0 deletions test/results/failure-simple-silent-no-curl-expected.txt
@@ -0,0 +1,4 @@
######### STDOUT #########
######### STDERR #########
Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found
######### EXIT 1 #########
3 changes: 2 additions & 1 deletion test/results/far-future-json--v-expected.txt
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -258,7 +259,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:18:05 GMT
Date: Tue, 20 Feb 2024 22:11:20 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 63
Expand Down
1 change: 1 addition & 0 deletions test/results/help--X_GET-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
1 change: 1 addition & 0 deletions test/results/help-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
1 change: 1 addition & 0 deletions test/results/help-missing-curl--X_GET-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
1 change: 1 addition & 0 deletions test/results/help-missing-curl-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
1 change: 1 addition & 0 deletions test/results/help-missing-curl-no-curl-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
1 change: 1 addition & 0 deletions test/results/help-no-curl-expected.txt
Expand Up @@ -41,6 +41,7 @@ Flags:
-i, --request-type string Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. Mandatory for POST requests. E.g. mypackage.MyRequest or ..MyRequest
-o, --response-type string The Protobuf response type. See -i <request-type>. Overrides --decode-raw. If not set, then --decode-raw is used.
-q, --show-output-only Suppresses all output except response Protobuf as text. Overrides and deactivates -v and -D. Errors are still printed to stderr.
-s, --silent Suppresses all output on stdout. Overrides and deactivates -v, -D and -q. Errors are still printed to stderr.
-u, --url string Mandatory: The url to send the request to
-v, --verbose Prints version and enables verbose output. Also activates -D.
--version version for protocurl
Expand Down
Expand Up @@ -23,6 +23,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -260,7 +261,7 @@ Total curl args:
=========================== GET Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:26 GMT
Date: Tue, 20 Feb 2024 22:10:44 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down
3 changes: 2 additions & 1 deletion test/results/inferred-message-package-path-expected.txt
Expand Up @@ -23,6 +23,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -260,7 +261,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:25 GMT
Date: Tue, 20 Feb 2024 22:10:44 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -325,7 +326,7 @@ Total curl args:
=========================== GET Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:38 GMT
Date: Tue, 20 Feb 2024 22:10:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -325,7 +326,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:38 GMT
Date: Tue, 20 Feb 2024 22:10:53 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down
3 changes: 2 additions & 1 deletion test/results/json-in-text-output--X_GET-expected.txt
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -258,7 +259,7 @@ Total curl args:
=========================== GET Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:48 GMT
Date: Tue, 20 Feb 2024 22:11:02 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down
3 changes: 2 additions & 1 deletion test/results/json-in-text-output-expected.txt
Expand Up @@ -24,6 +24,7 @@ Invoked with following default & parsed arguments:
"AdditionalCurlArgs": "",
"Verbose": true,
"ShowOutputOnly": false,
"SilentMode": false,
"ForceNoCurl": false,
"ForceCurl": false,
"GlobalProtoc": false,
Expand Down Expand Up @@ -258,7 +259,7 @@ Total curl args:
=========================== POST Response Headers =========================== <<<
HTTP/1.1 200 OK
Content-Type: application/x-protobuf
Date: Thu, 05 Oct 2023 09:17:48 GMT
Date: Tue, 20 Feb 2024 22:11:02 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 68
Expand Down

0 comments on commit 6b43a63

Please sign in to comment.