Skip to content

Commit

Permalink
update "Copy as cURL command" to be not verbose, and add "Copy as cUR…
Browse files Browse the repository at this point in the history
…L verbose command" for verbose
  • Loading branch information
sunny-chung committed Nov 24, 2024
1 parent 1efdcdc commit 423cd10
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- The main UI font has been changed to [Comme](https://github.com/googlefonts/comme) and unified among all platforms
- The main monospace font has been changed to [Pitagon Sans Mono](https://github.com/ThePitagon/pitagon-sans-mono) and unified among all platforms
- Importing CA certificates now imports all the certificates from an input file
- "Copy as cURL command" is now **non-verbose**, i.e. without `time` and `--verbose`. There is a new option "Copy as cURL verbose command" for verbose.
- Update the label of "Copy as PowerShell Invoke-WebRequest command" to confine supporting PowerShell version 6 or above only (there is no change to the underlying logic)
- Inherited values in Request Editor are now showing at the bottom rather than the top
- Number of space characters to indent or unindent in Request Body and Payload editors are changed from 4 to 2
Expand Down
22 changes: 11 additions & 11 deletions doc/features/command-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Some types of requests allow copying as shell commands. Click the dropdown menu

Supported operations are as follows:

| Request | Copying as verbose cURL commands | Copying as verbose [grpcurl](https://github.com/fullstorydev/grpcurl) commands | Copying as PowerShell Invoke-WebRequest command (for Windows pwsh.exe version 6 or above) |
|------------------------------|----------------------------------|--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| HTTP / REST | ✔︎ || ✔︎ |
| WebSocket ||||
| GraphQL Query | ✔︎ || ✔︎ |
| GraphQL Mutation | ✔︎ || ✔︎ |
| GraphQL Subscription ||||
| gRPC Unary || ✔︎ ||
| gRPC Client Streaming || ✔︎ ||
| gRPC Server Streaming || ✔︎ ||
| gRPC Bidirectional Streaming || ✔︎ ||
| Request | Copying as (verbose) cURL commands | Copying as verbose [grpcurl](https://github.com/fullstorydev/grpcurl) commands | Copying as PowerShell Invoke-WebRequest command (for Windows pwsh.exe version 6 or above) |
|------------------------------|------------------------------------|--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| HTTP / REST | ✔︎ || ✔︎ |
| WebSocket | |||
| GraphQL Query | ✔︎ || ✔︎ |
| GraphQL Mutation | ✔︎ || ✔︎ |
| GraphQL Subscription | |||
| gRPC Unary | | ✔︎ ||
| gRPC Client Streaming | | ✔︎ ||
| gRPC Server Streaming | | ✔︎ ||
| gRPC Bidirectional Streaming | | ✔︎ ||
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CommandGenerator(val os: OS) {
return URLEncoder.encode(this, StandardCharsets.UTF_8)
}

fun UserRequestTemplate.toCurlCommand(exampleId: String, environment: Environment?): String {
fun UserRequestTemplate.toCurlCommand(exampleId: String, environment: Environment?, isVerbose: Boolean): String {
val request = toHttpRequest(exampleId, environment)

val url = request.getResolvedUri().toString()
Expand All @@ -279,10 +279,13 @@ class CommandGenerator(val os: OS) {
val newLine = " ${currentOS.commandLineEscapeNewLine}\n "

var curl = ""
if (currentOS in setOf(MacOS, LinuxOS)) {
if (isVerbose) {
curl += "time "
}
curl += "curl --verbose"
curl += "curl"
if (isVerbose) {
curl += " --verbose"
}
if (environment?.sslConfig?.isInsecure == true) {
curl += "${newLine}--insecure"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,13 @@ fun AppContentView() {
onClickCancel = {
networkClientManager.cancel(selectedRequestExampleId!!)
},
onClickCopyCurl = {
onClickCopyCurl = { isVerbose ->
try {
val curl = with (CommandGenerator(LinuxOS)) {
requestNonNull.toCurlCommand(
exampleId = selectedRequestExampleId!!,
environment = selectedEnvironment
environment = selectedEnvironment,
isVerbose = isVerbose,
)
}
log.d { "curl: $curl" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fun RequestEditorView(
onSelectExample: (UserRequestExample) -> Unit,
onClickSend: () -> Unit,
onClickCancel: () -> Unit,
onClickCopyCurl: () -> Boolean,
onClickCopyCurl: (isVerbose: Boolean) -> Boolean,
onClickCopyGrpcurl: (selectedPayloadExampleId: String, method: GrpcMethod) -> Boolean,
onClickCopyPowershellInvokeWebrequest: () -> Boolean,
onRequestModified: (UserRequestTemplate?) -> Unit,
Expand Down Expand Up @@ -326,9 +326,9 @@ fun RequestEditorView(
}
val dropdownItems: List<SendButtonDropdown> = when (request.application) {
ProtocolApplication.WebSocket -> emptyList()
ProtocolApplication.Graphql -> if (isOneOffRequest) listOf(SendButtonDropdown.CurlForLinux, SendButtonDropdown.PowershellInvokeWebrequestForWindows) else emptyList()
ProtocolApplication.Graphql -> if (isOneOffRequest) listOf(SendButtonDropdown.CurlForLinux, SendButtonDropdown.CurlVerboseForLinux, SendButtonDropdown.PowershellInvokeWebrequestForWindows) else emptyList()
ProtocolApplication.Grpc -> listOf(SendButtonDropdown.GrpcurlForLinux)
else -> listOf(SendButtonDropdown.CurlForLinux, SendButtonDropdown.PowershellInvokeWebrequestForWindows)
else -> listOf(SendButtonDropdown.CurlForLinux, SendButtonDropdown.CurlVerboseForLinux, SendButtonDropdown.PowershellInvokeWebrequestForWindows)
}
val (label, backgroundColour) = if (!connectionStatus.isNotIdle()) {
Pair(if (isOneOffRequest) "Send" else "Connect", colors.backgroundButton)
Expand Down Expand Up @@ -373,7 +373,10 @@ fun RequestEditorView(
var isSuccess = true
when (it.displayText) {
SendButtonDropdown.CurlForLinux.displayText -> {
isSuccess = onClickCopyCurl()
isSuccess = onClickCopyCurl(false)
}
SendButtonDropdown.CurlVerboseForLinux.displayText -> {
isSuccess = onClickCopyCurl(true)
}
SendButtonDropdown.PowershellInvokeWebrequestForWindows.displayText -> {
isSuccess = onClickCopyPowershellInvokeWebrequest()
Expand Down Expand Up @@ -1801,6 +1804,7 @@ private data class ProtocolMethod(val application: ProtocolApplication, val meth

private enum class SendButtonDropdown(val displayText: String) {
CurlForLinux("Copy as cURL command (for Linux / macOS)"),
CurlVerboseForLinux("Copy as cURL verbose command (for Linux / macOS)"),
GrpcurlForLinux("Copy as grpcurl command (for Linux / macOS)"),
PowershellInvokeWebrequestForWindows("Copy as PowerShell v6+ Invoke-WebRequest command (for Windows pwsh.exe)")
}

0 comments on commit 423cd10

Please sign in to comment.