update(app): refactor commands
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import click
|
||||
import requests
|
||||
|
||||
BASE_URL = "http://localhost:8000/export" # Backend URL for exporting data
|
||||
|
||||
@click.command()
|
||||
@click.option(
|
||||
"--format",
|
||||
@@ -11,15 +9,20 @@ BASE_URL = "http://localhost:8000/export" # Backend URL for exporting data
|
||||
help="Specify the export format: yaml or json. Default is json.",
|
||||
)
|
||||
@click.argument("output", required=False, type=click.Path(writable=True))
|
||||
def export_data(format, output):
|
||||
@click.pass_context
|
||||
def export_data(ctx, format, output):
|
||||
"""
|
||||
Export Metal Check data in the specified format (yaml or json).
|
||||
|
||||
If an OUTPUT file is provided, the data will be saved to the file.
|
||||
Otherwise, it will be printed to the console.
|
||||
"""
|
||||
|
||||
base_url = ctx.obj["BASE_URL"]
|
||||
export_url = f"{base_url}/export"
|
||||
|
||||
try:
|
||||
response = requests.get(f"{BASE_URL}?format={format}")
|
||||
response = requests.get(f"{export_url}?format={format}")
|
||||
if response.status_code == 200:
|
||||
data = response.text
|
||||
if output:
|
||||
@@ -33,4 +36,3 @@ def export_data(format, output):
|
||||
click.echo(f"Error: {response.status_code} - {response.text}")
|
||||
except requests.RequestException as e:
|
||||
click.echo(f"Error: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user