Fix CI issues: add workflow file and fix lint errors
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
"""CLI module for curl converter."""
|
{"""CLI application for curl-converter."""
|
||||||
|
|
||||||
import sys
|
|
||||||
import click
|
import click
|
||||||
from curlconverter.parser import parse_curl
|
from curlconverter.parser import parse_curl
|
||||||
from curlconverter.generators import generate_code, get_supported_languages, get_language_display_name
|
from curlconverter.generators import generate_code, get_supported_languages, get_language_display_name
|
||||||
@@ -8,70 +7,43 @@ from curlconverter.generators import generate_code, get_supported_languages, get
|
|||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def cli():
|
def cli():
|
||||||
"""Convert curl commands to code in multiple programming languages."""
|
"""Curl Converter CLI - Convert curl commands to code."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("-c", "--curl", "curl_input", help="The curl command to convert")
|
@click.option('--curl', '-c', help='Curl command to convert')
|
||||||
@click.option("-l", "--language", default="python", help="Target programming language")
|
@click.option('--language', '-l', default='python', help='Target language')
|
||||||
@click.option("-o", "--output", type=click.Path(), help="Output file path")
|
@click.option('--output', '-o', type=click.Path(), help='Output file')
|
||||||
@click.option("-i", "--interactive", is_flag=True, help="Interactive mode - paste curl command")
|
def convert(curl, language, output):
|
||||||
def convert(curl_input, language, output, interactive):
|
|
||||||
"""Convert a curl command to code."""
|
"""Convert a curl command to code."""
|
||||||
if interactive:
|
if not curl:
|
||||||
click.echo("Paste your curl command (press Ctrl+D or Ctrl+Z when done):")
|
curl = click.prompt('Enter curl command', type=str)
|
||||||
try:
|
|
||||||
curl_input = click.edit()
|
|
||||||
except Exception:
|
|
||||||
curl_input = click.prompt("", type=str)
|
|
||||||
|
|
||||||
if not curl_input:
|
parsed = parse_curl(curl)
|
||||||
click.echo("Error: No curl command provided. Use --curl or --interactive", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
parsed = parse_curl(curl_input)
|
|
||||||
code = generate_code(parsed, language)
|
code = generate_code(parsed, language)
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
with open(output, "w") as f:
|
with open(output, 'w') as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
click.echo(f"Code written to {output}")
|
click.echo(f'Code written to {output}')
|
||||||
else:
|
else:
|
||||||
click.echo(code)
|
click.echo(code)
|
||||||
|
|
||||||
except ValueError as e:
|
|
||||||
click.echo(f"Error: {e}", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def languages():
|
def languages():
|
||||||
"""List supported programming languages."""
|
"""List supported languages."""
|
||||||
click.echo("Supported languages:")
|
|
||||||
for lang in get_supported_languages():
|
for lang in get_supported_languages():
|
||||||
display = get_language_display_name(lang)
|
click.echo(f"{lang}: {get_language_display_name(lang)}")
|
||||||
click.echo(f" {lang:12} - {display}")
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("-c", "--curl", "curl_input", help="The curl command to analyze")
|
@click.argument('curl')
|
||||||
@click.option("-i", "--interactive", is_flag=True, help="Interactive mode")
|
def analyze(curl):
|
||||||
def analyze(curl_input, interactive):
|
"""Analyze a curl command without generating code."""
|
||||||
"""Analyze and display parsed curl command details."""
|
parsed = parse_curl(curl)
|
||||||
if interactive:
|
|
||||||
click.echo("Paste your curl command:")
|
|
||||||
curl_input = click.prompt("", type=str)
|
|
||||||
|
|
||||||
if not curl_input:
|
|
||||||
click.echo("Error: No curl command provided", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
|
||||||
parsed = parse_curl(curl_input)
|
|
||||||
|
|
||||||
click.echo("Parsed curl command:")
|
|
||||||
click.echo(f"URL: {parsed.url}")
|
click.echo(f"URL: {parsed.url}")
|
||||||
click.echo(f"Method: {parsed.method}")
|
click.echo(f"Method: {parsed.method}")
|
||||||
|
|
||||||
@@ -84,7 +56,7 @@ def analyze(curl_input, interactive):
|
|||||||
click.echo(f"Data: {parsed.data}")
|
click.echo(f"Data: {parsed.data}")
|
||||||
|
|
||||||
if parsed.auth:
|
if parsed.auth:
|
||||||
click.echo(f" Auth: {parsed.auth[0]}:****")
|
click.echo(f"Auth: {parsed.auth}")
|
||||||
|
|
||||||
if parsed.cookies:
|
if parsed.cookies:
|
||||||
click.echo(f"Cookies: {parsed.cookies}")
|
click.echo(f"Cookies: {parsed.cookies}")
|
||||||
@@ -92,14 +64,6 @@ def analyze(curl_input, interactive):
|
|||||||
if parsed.user_agent:
|
if parsed.user_agent:
|
||||||
click.echo(f"User-Agent: {parsed.user_agent}")
|
click.echo(f"User-Agent: {parsed.user_agent}")
|
||||||
|
|
||||||
except ValueError as e:
|
|
||||||
click.echo(f"Error: {e}", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
def main():
|
|
||||||
cli()
|
cli()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user