Any library that will parse curl options?

Elixir has OptionParser built in but I just wanted it to use it to parse a curl request copied from a browser:

"""
curl 'https://elixirforum.com/c/questions-help/53' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'DNT: 1' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'Sec-Fetch-Dest: document' \
-H 'Sec-Fetch-Mode: navigate' \
-H 'Sec-Fetch-Site: none' \
-H 'Sec-Fetch-User: ?1' \
-H 'Connection: keep-alive' \
-H 'User-Agent: Mozilla/5.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9'
"""
|> OptionParser.split()
|> Enum.drop(2)
|> OptionParser.parse(aliases: [H: :header], strict: [header: :string])
{[header: "Accept: text/html,application/xhtml+xml,application/xml;q=0.9\n"], [], []}

and it only gives me the last header, if this is a keyword list I would expect to have all the headers - are there any alternatives ?

There is a :keep modifier you can use :slight_smile:

iex(1)> OptionParser.parse!(["--header", "foo", "--header", "bar"], strict: [header: [:string, :keep]])
{[header: "foo", header: "bar"], []}
iex(2)>
2 Likes

thanks - I missed that