This commit is contained in:
152
README.md
152
README.md
@@ -1,158 +1,50 @@
|
|||||||
# curl-to-code-converter
|
# curl-to-code-converter
|
||||||
|
|
||||||
A CLI tool that converts cURL commands into ready-to-use code snippets in multiple programming languages. Simply paste a cURL command and get clean, formatted code with proper headers, authentication, and body handling.
|
A CLI tool that converts cURL commands into code snippets in various programming languages.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Convert cURL to Python (requests)
|
- Convert cURL to Python requests code
|
||||||
- Convert cURL to JavaScript (fetch)
|
- Convert cURL to JavaScript fetch code
|
||||||
- Convert cURL to Go (net/http)
|
- Convert cURL to Go HTTP code
|
||||||
- Convert cURL to Ruby (Net::HTTP)
|
- Convert cURL to Ruby Net::HTTP code
|
||||||
- Convert cURL to PHP (cURL)
|
|
||||||
- Convert cURL to Java (HttpURLConnection)
|
|
||||||
- Support for headers, authentication, JSON body
|
- Support for headers, authentication, JSON body
|
||||||
- Interactive CLI with verbose output
|
- Interactive mode for pasting cURL directly
|
||||||
- Output to file or stdout
|
- Copy to clipboard functionality
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Install from source
|
|
||||||
pip install -e .
|
|
||||||
|
|
||||||
# Or install directly
|
|
||||||
pip install curl-to-code-converter
|
pip install curl-to-code-converter
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Basic Conversion
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Convert to Python (default)
|
|
||||||
curl-to-code 'curl https://api.example.com/data'
|
curl-to-code 'curl https://api.example.com/data'
|
||||||
|
curl-to-code 'curl -X POST https://api.example.com -d "{\"key\":\"value\"}"' -l python
|
||||||
# Convert to JavaScript
|
|
||||||
curl-to-code 'curl https://api.example.com/data' -l javascript
|
|
||||||
|
|
||||||
# Convert to Go
|
|
||||||
curl-to-code 'curl https://api.example.com/data' -l go
|
|
||||||
|
|
||||||
# Convert to Ruby
|
|
||||||
curl-to-code 'curl https://api.example.com/data' -l ruby
|
|
||||||
|
|
||||||
# Convert to PHP
|
|
||||||
curl-to-code 'curl https://api.example.com/data' -l php
|
|
||||||
|
|
||||||
# Convert to Java
|
|
||||||
curl-to-code 'curl https://api.example.com/data' -l java
|
|
||||||
```
|
|
||||||
|
|
||||||
### With Headers and Data
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# POST with JSON body
|
|
||||||
curl-to-code 'curl -X POST https://api.example.com -H "Content-Type: application/json" -d "{\"key\":\"value\"}"' -l python
|
|
||||||
|
|
||||||
# With authentication
|
|
||||||
curl-to-code 'curl -u user:pass https://api.example.com' -l python
|
|
||||||
|
|
||||||
# With custom headers
|
|
||||||
curl-to-code 'curl -H "Authorization: Bearer token" https://api.example.com' -l javascript
|
curl-to-code 'curl -H "Authorization: Bearer token" https://api.example.com' -l javascript
|
||||||
```
|
```
|
||||||
|
|
||||||
### Output Options
|
## Options
|
||||||
|
|
||||||
```bash
|
- `-l, --language`: Target programming language (default: python)
|
||||||
# Write to file
|
- `-o, --output`: Output file path
|
||||||
curl-to-code 'curl https://api.example.com' -o output.py
|
- `-v, --verbose`: Show verbose output
|
||||||
|
|
||||||
# Verbose output (shows parsed details)
|
## Supported Languages
|
||||||
curl-to-code 'curl https://api.example.com' --verbose
|
|
||||||
```
|
|
||||||
|
|
||||||
## Supported Options
|
- Python (requests)
|
||||||
|
- JavaScript (fetch)
|
||||||
|
- Go (net/http)
|
||||||
|
- Ruby (Net::HTTP)
|
||||||
|
- PHP (cURL)
|
||||||
|
- Java (HttpURLConnection)
|
||||||
|
|
||||||
| Option | Description |
|
## Contributing
|
||||||
|--------|-------------|
|
|
||||||
| `-l, --language` | Target language (python, javascript, go, ruby, php, java) |
|
|
||||||
| `-o, --output` | Output file path |
|
|
||||||
| `-v, --verbose` | Show verbose output |
|
|
||||||
|
|
||||||
## Supported cURL Options
|
Contributions welcome! Please read the contributing guidelines.
|
||||||
|
|
||||||
- `-X, --request` - HTTP method
|
|
||||||
- `-H, --header` - Custom headers
|
|
||||||
- `-d, --data` - Request body
|
|
||||||
- `-u, --user` - Basic authentication
|
|
||||||
- `-A, --user-agent` - User agent header
|
|
||||||
- `--compressed` - Accept-Encoding header
|
|
||||||
- `-k, --insecure` - Skip SSL verification
|
|
||||||
- `-b, --cookie` - Cookie header
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
### Python Output
|
|
||||||
```python
|
|
||||||
import requests
|
|
||||||
|
|
||||||
response = requests.post(
|
|
||||||
'https://api.example.com/data',
|
|
||||||
headers={'Content-Type': 'application/json'},
|
|
||||||
json={'key': 'value'}
|
|
||||||
)
|
|
||||||
|
|
||||||
print(response.status_code)
|
|
||||||
print(response.text)
|
|
||||||
```
|
|
||||||
|
|
||||||
### JavaScript Output
|
|
||||||
```javascript
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
const options = {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'Content-Type': 'application/json'},
|
|
||||||
body: JSON.stringify({'key': 'value'})
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await fetch('https://api.example.com/data', options);
|
|
||||||
const data = await response.json();
|
|
||||||
console.log(data);
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
```
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Clone the repository
|
|
||||||
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/curl-to-code-converter.git
|
|
||||||
cd curl-to-code-converter
|
|
||||||
|
|
||||||
# Install in development mode
|
|
||||||
pip install -e .
|
|
||||||
|
|
||||||
# Run tests
|
|
||||||
pytest tests/ -v
|
|
||||||
|
|
||||||
# Lint
|
|
||||||
ruff check .
|
|
||||||
|
|
||||||
# Type check
|
|
||||||
mypy curl_to_code_converter --ignore-missing-imports
|
|
||||||
```
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- Python 3.7+
|
|
||||||
- requests
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT License
|
||||||
|
|||||||
Reference in New Issue
Block a user