Skip to content

Commit 9641b26

Browse files
authored
refactor: ♻️ make report default cmd (#65)
* refactor: ♻️ make report default cmd CLI app only has a single command, so make it the default action when opening the app * pr comment
1 parent 73ecf41 commit 9641b26

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ flowchart TD
2828
The CLI entry point uses Typer for command-line interface management. It:
2929
- Loads configuration from TOML files, environment variables, or CLI arguments
3030
- Initializes the application state (`AppState`)
31-
- Delegates to the `report` command for TVL reporting
31+
- Executes the TVL reporting pipeline as the default command
3232

3333
**Key Configuration:**
3434

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,37 @@ See `tq-oracle-example.toml` for complete configuration examples.
123123

124124
### Usage Examples
125125

126-
> [!IMPORTANT]
127-
> Until Mellow has deployments of the vaults available for testing, you may need to use `--ignore-empty-vault` flag to overcome empty-asset errors.
126+
**Run with auto-detected config file:**
127+
128+
```bash
129+
# Loads from tq-oracle.toml or ~/.config/tq-oracle/config.toml
130+
tq-oracle
131+
```
132+
133+
**Run with explicit vault address:**
134+
135+
```bash
136+
# Override vault address from config
137+
tq-oracle 0xYourVaultAddress
138+
```
139+
140+
**Run with custom config file:**
141+
142+
```bash
143+
tq-oracle --config path/to/custom-config.toml
144+
```
145+
146+
**Run with network override:**
147+
148+
```bash
149+
tq-oracle --network sepolia 0xYourVaultAddress
150+
```
151+
152+
**Preview configuration without running:**
153+
154+
```bash
155+
tq-oracle --show-config
156+
```
128157

129158
**Common Usage Patterns:**
130159

src/tq_oracle/main.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import asyncio
66
import json
77
import logging
8+
import os
89
from pathlib import Path
910
from typing import Annotated
1011

1112
import typer
12-
1313
from web3 import Web3
1414

1515
from .constants import (
@@ -40,11 +40,12 @@
4040

4141
app = typer.Typer(
4242
add_completion=False,
43-
no_args_is_help=True,
43+
no_args_is_help=False,
4444
add_help_option=True,
4545
pretty_exceptions_enable=True,
4646
pretty_exceptions_short=True,
4747
pretty_exceptions_show_locals=False,
48+
rich_markup_mode="rich",
4849
help="TVL reporting and Safe submission tool.",
4950
)
5051

@@ -59,9 +60,11 @@ def _redacted_dump(settings: OracleSettings) -> dict:
5960
return settings.as_safe_dict()
6061

6162

62-
@app.callback()
63-
def initialize_context(
64-
ctx: typer.Context,
63+
@app.callback(invoke_without_command=True)
64+
def report(
65+
vault_address: Annotated[
66+
str | None, typer.Argument(help="Vault address to report.")
67+
] = None,
6568
config_path: Annotated[
6669
Path | None,
6770
typer.Option(
@@ -121,14 +124,11 @@ def initialize_context(
121124
),
122125
] = False,
123126
):
124-
"""Typer callback to initialize application state before any subcommand executes.
127+
"""Build a TVL report and (optionally) submit to Safe.
125128
126-
This function runs automatically before commands like 'report'. It loads configuration,
127-
applies network-specific defaults, and stores the initialized AppState in ctx.obj
128-
for subcommands to access.
129+
This is the default command that loads configuration, applies network-specific
130+
defaults, validates settings, and executes the TVL reporting pipeline.
129131
"""
130-
import os
131-
132132
if config_path:
133133
os.environ["TQ_ORACLE_CONFIG"] = str(config_path)
134134

@@ -183,52 +183,39 @@ def initialize_context(
183183

184184
setup_logging(settings.log_level)
185185
logger = _build_logger()
186-
187-
ctx.obj = AppState(settings=settings, logger=logger)
186+
state = AppState(settings=settings, logger=logger)
188187

189188
if show_config:
190189
typer.echo(json.dumps(_redacted_dump(settings), indent=2))
191190
raise typer.Exit(code=0)
192191

193-
194-
@app.command()
195-
def report(
196-
ctx: typer.Context,
197-
vault_address: Annotated[
198-
str | None, typer.Argument(help="Vault address to report.")
199-
] = None,
200-
):
201-
"""Build a TVL report and (optionally) submit to Safe."""
202-
state: AppState = ctx.obj
203-
s = state.settings
204-
205192
if vault_address:
206-
s.vault_address = vault_address
193+
state.settings.vault_address = vault_address
207194

208-
if not s.vault_address:
195+
if not state.settings.vault_address:
209196
raise typer.BadParameter("vault_address must be configured")
210-
if not s.vault_rpc:
197+
if not state.settings.vault_rpc:
211198
raise typer.BadParameter("vault_rpc must be configured")
212-
if not s.oracle_helper_address:
199+
if not state.settings.oracle_helper_address:
213200
raise typer.BadParameter("oracle_helper_address must be configured")
214-
if not s.hl_rpc:
201+
if not state.settings.hl_rpc:
215202
raise typer.BadParameter("hl_rpc must be configured")
216203

217-
if not s.dry_run:
218-
if not s.safe_address:
204+
if not state.settings.dry_run:
205+
if not state.settings.safe_address:
219206
raise typer.BadParameter(
220207
"safe_address is required when running with --no-dry-run.",
221208
param_hint=["--safe-address", "TQ_ORACLE_SAFE_ADDRESS"],
222209
)
223-
if not s.private_key:
210+
if not state.settings.private_key:
224211
raise typer.BadParameter(
225212
"private_key is required when running with --no-dry-run.",
226213
param_hint=["--private-key", "TQ_ORACLE_PRIVATE_KEY"],
227214
)
228215

229216
from .pipeline.run import run_report
230217

231-
asyncio.run(run_report(state, s.vault_address_required))
218+
asyncio.run(run_report(state, state.settings.vault_address_required))
232219

233220

234221
def run() -> None:

0 commit comments

Comments
 (0)