# curl-to-code-cli Convert curl commands to code in multiple programming languages. ## Features - **Multiple Language Support**: Generate Python (requests), JavaScript (fetch), Go (net/http), Rust (reqwest), and PHP (cURL) code - **Interactive Mode**: Enter multiple curl commands without re-running the CLI - **Syntax Highlighting**: Colorful code output for better readability - **Comprehensive Parsing**: Supports headers, authentication, JSON data, cookies, and more ## Installation ```bash pip install curl-to-code ``` Or install from source: ```bash git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/curl-to-code-cli.git cd curl-to-code-cli pip install -e . ``` ## Usage ### Basic Conversion Convert a curl command to Python: ```bash curl-to-code "curl https://api.example.com/users" ``` Convert to a specific language: ```bash curl-to-code "curl https://api.example.com/users" --lang javascript ``` ### Supported Languages | Flag | Language | Library | |------|----------|---------| | `python` / `py` | Python | requests | | `javascript` / `js` | JavaScript | fetch | | `go` / `golang` | Go | net/http | | `rust` | Rust | reqwest | | `php` | PHP | cURL | ### Interactive Mode Enter interactive mode for multiple conversions: ```bash curl-to-code interactive --lang python ``` ### Disable Syntax Highlighting ```bash curl-to-code "curl https://api.example.com" --no-highlight ``` ### List Supported Languages ```bash curl-to-code languages ``` ## Examples ### Simple GET Request Input: ```bash curl-to-code "curl https://api.example.com/users" ``` Output (Python): ```python import requests from requests.auth import HTTPBasicAuth import json def make_request(): url = "https://api.example.com/users" auth = None headers = {} response = requests.get(url, headers=headers, auth=auth) try: response.raise_for_status() print(response.json()) except requests.exceptions.RequestException as e: print(f"Error: {e}") except ValueError as e: print(f"JSON decode error: {e}") if __name__ == "__main__": make_request() ``` ### POST with JSON Data Input: ```bash curl-to-code "curl -X POST -H 'Content-Type: application/json' -d '{\"name\":\"test\"}' https://api.example.com/users" ``` ### Request with Authentication Input: ```bash curl-to-code "curl -u user:password https://api.example.com" ``` ### Request with Custom Headers Input: ```bash curl-to-code "curl -H 'Authorization: Bearer token123' https://api.example.com" ``` ## Supported curl Options | Option | Description | |--------|-------------| | `-X`, `--request` | HTTP method (GET, POST, PUT, PATCH, DELETE, etc.) | | `-H`, `--header` | Custom HTTP header | | `-d`, `--data` | Request body data | | `--data-json` | JSON request body | | `-u`, `--user` | Basic authentication | | `--bearer` | Bearer token authentication | | `-b`, `--cookie` | Cookies | | `-A`, `--user-agent` | User-Agent header | | `--url` | Explicit URL | | `-L` | Follow redirects | | `--connect-timeout` | Connection timeout in seconds | ## Development ### Setup ```bash git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/curl-to-code-cli.git cd curl-to-code-cli pip install -e ".[dev]" ``` ### Running Tests ```bash pytest tests/ -v ``` ### Linting ```bash ruff check . ``` ## License MIT License