#cmd #nom #curl #parser #command-line

bin+lib nomcurl

nomcurl is a library written in Rust that uses the nom library to parse cURL commands. It can handle various cURL options, including methods, headers, data, and flags.

1 unstable release

0.1.8 Oct 18, 2024

#57 in #curl

Download history 117/week @ 2024-10-14 15/week @ 2024-10-21

132 downloads per month

MIT license

39KB
859 lines

nom-curl: A cURL Command Parser in Rust

中文 | English

nom-curl is a Rust library for parsing cURL commands using the nom parser combinator library. It can handle various cURL options, including methods, headers, data, and flags.

Features

  • Parse cURL command line options.
  • Support for common cURL methods such as -X, -H, -d, etc.
  • Ability to handle quoted data and URLs.
  • Provides a flexible API for extending new cURL options.

Installation

Add nom-curl to your Cargo.toml file:

[dependencies]
nom-curl = "0.1.8"

Usage

use nom_curl::parsers::curl_cmd_parse;

fn main() {
    let curl_command = "curl 'http://example.com' -X GET -H 'Accept: application/json'";
    let result = curl_cmd_parse(curl_command);
    println!("{:?}", result);
}

Documentation

For detailed API documentation and guides, visit here.

Examples

Parsing a Simple cURL Command

use nom_curl::parsers::curl_cmd_parse;

let curl_command = "curl 'http://example.com' -X GET";
let result = curl_cmd_parse(curl_command);
assert!(result.is_ok());

Parsing a cURL Command with Data

use nom_curl::parsers::curl_cmd_parse;

let curl_command = "curl 'http://example.com' -d 'name=John&age=30'";
let result = curl_cmd_parse(curl_command);
assert!(result.is_ok());

Contributing

We welcome any contributions! Please review the contribution guidelines before submitting a pull request.

License

nom-curl is released under the MIT license.

Dependencies

~1MB
~19K SLoC