Initial upload: curl-to-code-converter CLI tool
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
157
README.md
157
README.md
@@ -1,3 +1,158 @@
|
||||
# curl-to-code-converter
|
||||
|
||||
A CLI tool that converts cURL commands into code snippets in Python, JavaScript, Go, Ruby, PHP, and Java
|
||||
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.
|
||||
|
||||
## Features
|
||||
|
||||
- Convert cURL to Python (requests)
|
||||
- Convert cURL to JavaScript (fetch)
|
||||
- Convert cURL to Go (net/http)
|
||||
- Convert cURL to Ruby (Net::HTTP)
|
||||
- Convert cURL to PHP (cURL)
|
||||
- Convert cURL to Java (HttpURLConnection)
|
||||
- Support for headers, authentication, JSON body
|
||||
- Interactive CLI with verbose output
|
||||
- Output to file or stdout
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Install from source
|
||||
pip install -e .
|
||||
|
||||
# Or install directly
|
||||
pip install curl-to-code-converter
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Conversion
|
||||
|
||||
```bash
|
||||
# Convert to Python (default)
|
||||
curl-to-code 'curl https://api.example.com/data'
|
||||
|
||||
# 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
|
||||
```
|
||||
|
||||
### Output Options
|
||||
|
||||
```bash
|
||||
# Write to file
|
||||
curl-to-code 'curl https://api.example.com' -o output.py
|
||||
|
||||
# Verbose output (shows parsed details)
|
||||
curl-to-code 'curl https://api.example.com' --verbose
|
||||
```
|
||||
|
||||
## Supported Options
|
||||
|
||||
| Option | Description |
|
||||
|--------|-------------|
|
||||
| `-l, --language` | Target language (python, javascript, go, ruby, php, java) |
|
||||
| `-o, --output` | Output file path |
|
||||
| `-v, --verbose` | Show verbose output |
|
||||
|
||||
## Supported cURL Options
|
||||
|
||||
- `-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
|
||||
|
||||
MIT
|
||||
|
||||
Reference in New Issue
Block a user