-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig.py
More file actions
70 lines (56 loc) · 2.09 KB
/
config.py
File metadata and controls
70 lines (56 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Config management commands."""
import typer
from pumpfun_cli.core.config import KNOWN_KEYS, delete_config_value, load_config, save_config_value
from pumpfun_cli.group import JsonAwareGroup
from pumpfun_cli.output import error, render
app = typer.Typer(
help="Manage CLI configuration.", invoke_without_command=True, cls=JsonAwareGroup
)
@app.callback()
def _config_callback(ctx: typer.Context):
if ctx.invoked_subcommand is None:
typer.echo(ctx.get_help())
raise SystemExit(0)
@app.command("set")
def config_set(ctx: typer.Context, key: str, value: str):
"""Set a config value."""
if key not in KNOWN_KEYS:
error(
f"Unknown config key: {key}",
hint=f"Valid keys: {', '.join(sorted(KNOWN_KEYS))}",
)
save_config_value(key, value)
json_mode = ctx.obj.json_mode if ctx.obj else False
if not render({"key": key, "value": value, "status": "saved"}, json_mode):
typer.echo(f"Saved {key}.")
@app.command("get")
def config_get(ctx: typer.Context, key: str):
"""Get a config value."""
config = load_config()
val = config.get(key)
if val is None:
error(f"Key '{key}' not set.", hint="Run: pumpfun config list")
json_mode = ctx.obj.json_mode if ctx.obj else False
if not render({"key": key, "value": val}, json_mode):
typer.echo(val)
@app.command("list")
def config_list(ctx: typer.Context):
"""List all config values."""
config = load_config()
state = ctx.obj
json_mode = state.json_mode if state else False
if not render(config, json_mode):
if not config:
typer.echo("No config values set.")
for k, v in config.items():
typer.echo(f"{k} = {v}")
@app.command("delete")
def config_delete(ctx: typer.Context, key: str):
"""Delete a config value."""
try:
delete_config_value(key)
except KeyError:
error(f"Key '{key}' not set.", hint="Run: pumpfun config list")
json_mode = ctx.obj.json_mode if ctx.obj else False
if not render({"key": key, "status": "deleted"}, json_mode):
typer.echo(f"Deleted {key}.")