From 8d65413c7bfa0d3dc27712512047bb9c61afebdb Mon Sep 17 00:00:00 2001 From: Daniel Karpelevitch Date: Wed, 9 Apr 2025 03:00:45 -0700 Subject: [PATCH 1/2] make raw `yna` call redirect to `yna ynamazon` but without the option to add command-line args --- src/ynamazon/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ynamazon/cli.py b/src/ynamazon/cli.py index ce328ce..cd6c309 100644 --- a/src/ynamazon/cli.py +++ b/src/ynamazon/cli.py @@ -1,4 +1,5 @@ # ruff: noqa: D212, D415 +import sys from typing import Annotated from rich.console import Console @@ -168,3 +169,14 @@ def ynamazon( ynab_config=Configuration(access_token=ynab_api_key), budget_id=ynab_budget_id, ) + + +@cli.callback(invoke_without_command=True) +def yna_callback() -> None: + if len(sys.argv) == 1: + ynamazon( + ynab_api_key=settings.ynab_api_key.get_secret_value(), + ynab_budget_id=settings.ynab_budget_id.get_secret_value(), + amazon_user=settings.amazon_user, + amazon_password=settings.amazon_password.get_secret_value(), + ) # run with .arg values only, if you need to pass in other values, use `yna ynamazon [args]` instead From e9c2ca81880cad886ab783d6505689a4a8bd5fb1 Mon Sep 17 00:00:00 2001 From: Daniel Karpelevitch Date: Wed, 9 Apr 2025 14:29:44 -0700 Subject: [PATCH 2/2] new (cleaner) appoach to detecting no commands --- src/ynamazon/cli.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ynamazon/cli.py b/src/ynamazon/cli.py index cd6c309..73a731c 100644 --- a/src/ynamazon/cli.py +++ b/src/ynamazon/cli.py @@ -1,11 +1,13 @@ # ruff: noqa: D212, D415 -import sys from typing import Annotated from rich.console import Console from rich.table import Table from typer import Argument, Option, Typer from ynab import Configuration +from typer import Context +from typer import run as typer_run +from rich import print as rprint from .amazon_transactions import AmazonConfig, get_amazon_transactions from .main import process_transactions @@ -172,11 +174,12 @@ def ynamazon( @cli.callback(invoke_without_command=True) -def yna_callback() -> None: - if len(sys.argv) == 1: - ynamazon( - ynab_api_key=settings.ynab_api_key.get_secret_value(), - ynab_budget_id=settings.ynab_budget_id.get_secret_value(), - amazon_user=settings.amazon_user, - amazon_password=settings.amazon_password.get_secret_value(), - ) # run with .arg values only, if you need to pass in other values, use `yna ynamazon [args]` instead +def yna_callback(ctx: Context) -> None: + """ + [bold cyan]Run 'yna' to match and update transactions using the arguements in .env. [/] + + [yellow i]Use 'yna ynamazon [ARGS]' to use command-line arguements to override .env. [/] + """ + rprint("[bold cyan]Starting YNAmazon processing...[/]") + if ctx.invoked_subcommand is None: + typer_run(function=ynamazon)