nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: derekkraan/curl_req
Pull request #3 (2024-06-04 07:26:40)

Handle multiple -d/--data flags
The long form flag was corrected to `--data` instead of `--body`.
It now joins the string with an `&` as described in the man pages.


Patch:
diff --git a/README.md b/README.md
index 7c7f6ff..8e03022 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ Contributions are welcome! There are gaps in the library, and this is open sourc
 - [x] curl -X
 - [x] curl -d
 - [ ] curl -b
-- [x] curl long form options (--header, --body, etc)
+- [x] curl long form options (--header, --data, etc)
 - [ ] Req Plugin to log curl command (like `TeslaCurl`)
 
 ## How to contribute
diff --git a/lib/curl_req/macro.ex b/lib/curl_req/macro.ex
index a4f3224..041b722 100644
--- a/lib/curl_req/macro.ex
+++ b/lib/curl_req/macro.ex
@@ -3,7 +3,6 @@ defmodule CurlReq.Macro do
 
   # TODO: handle newlines
   # TODO: support -b (cookies)
-  # TODO: support multiple -d
 
   def parse(command) do
     command =
@@ -15,8 +14,8 @@ defmodule CurlReq.Macro do
       command
       |> OptionParser.split()
       |> OptionParser.parse(
-        strict: [header: :keep, request: :string, body: :string],
-        aliases: [H: :header, X: :request, d: :body]
+        strict: [header: :keep, request: :string, data: :keep],
+        aliases: [H: :header, X: :request, d: :data]
       )
 
     url = String.trim(url)
@@ -56,7 +55,12 @@ defmodule CurlReq.Macro do
   end
 
   defp add_body(req, options) do
-    body = Keyword.get(options, :body)
+    body =
+      case Keyword.get_values(options, :data) do
+        [] -> nil
+        data -> Enum.join(data, "&")
+      end
+
     Req.merge(req, body: body)
   end
 end


Test patch:
diff --git a/test/curl_req_test.exs b/test/curl_req_test.exs
index 8a4d47b..017a759 100644
--- a/test/curl_req_test.exs
+++ b/test/curl_req_test.exs
@@ -44,5 +44,13 @@ defmodule CurlReqTest do
                  url: URI.parse("http://localhost")
                }
     end
+
+    test "multiple data flags" do
+      assert ~CURL(curl http://example.com -d name=foo -d mail=bar) ==
+               %Req.Request{
+                 url: URI.parse("http://example.com"),
+                 body: "name=foo&mail=bar"
+               }
+    end
   end
 end
Repository: derekkraan/curl_req
Pull request #37 (2025-01-13 09:59:02)

Add more common flags
To make parsing more stable because the flags are often used. We currently don't use them because they are describing the runtime behaviour and not how the request itself is built/configured. 


Patch:
diff --git a/lib/curl_req/curl.ex b/lib/curl_req/curl.ex
index 7acbcef..c6d9bf1 100644
--- a/lib/curl_req/curl.ex
+++ b/lib/curl_req/curl.ex
@@ -22,7 +22,12 @@ defmodule CurlReq.Curl do
     netrc: :boolean,
     netrc_file: :string,
     insecure: :boolean,
-    user_agent: :string
+    user_agent: :string,
+    fail: :boolean,
+    silent: :boolean,
+    show_error: :boolean,
+    output: :string,
+    remote_name: :boolean
   ]
 
   @aliases [
@@ -38,7 +43,12 @@ defmodule CurlReq.Curl do
     U: :proxy_user,
     n: :netrc,
     k: :insecure,
-    A: :user_agent
+    A: :user_agent,
+    f: :fail,
+    s: :silent,
+    S: :show_error,
+    o: :output,
+    O: :remote_name
   ]
 
   @doc """


Test patch:
diff --git a/test/curl_req_test.exs b/test/curl_req_test.exs
index 5d0b4e4..9af1037 100644
--- a/test/curl_req_test.exs
+++ b/test/curl_req_test.exs
@@ -627,6 +627,16 @@ defmodule CurlReqTest do
              """
     end
 
+    test "unused flags get ignored" do
+      # we don't need an assertion because if we couldn't parse the flag we would throw an exception and the test would fail
+      CurlReq.Curl.decode(~s(curl -o "somefile" https://example.com))
+      CurlReq.Curl.decode(~s(curl -O https://example.com))
+      CurlReq.Curl.decode(~s(curl -s https://example.com))
+      CurlReq.Curl.decode(~s(curl -S https://example.com))
+      CurlReq.Curl.decode(~s(curl -f https://example.com))
+      CurlReq.Curl.decode(~s(curl -fsS https://example.com))
+    end
+
     test "raises on unsupported flag" do
       assert_raise ArgumentError, ~r/Unknown "--foo"/, fn ->
         CurlReq.Curl.decode(~s(curl --foo https://example.com))