Skip to content

Conversation

@Mathious6
Copy link
Collaborator

Why?

The builder API in main.rs was getting long and hard to understand, with derive + typed fields (with validators) we will reduce runtime parsing bugs. Regarding tests, a single Cli struct is easy to unit test.

What?

  • New: src/cli.rs defines the full CLI using clap’s derive API.
  • Validation at parse time:
    • account / from / to now validated as 32 hex chars (parse_account_id).
    • quantity validated as >= 1.
  • Documentation cleanup: minor help text polish, clearer examples.

Note

I considered introducing an AccountId newtype (with FromStr) now, but left it for a follow-up to keep this PR focused and small.

Main impact?

  • End users: no behavior change; --help is cleaner. Old flags still work via visible aliases.
  • Developers: CLI shape is defined in one place (cli.rs). The dispatcher in lib.rs keeps working because argument IDs are unchanged.
  • Safety: invalid account IDs and zero quantities are rejected earlier with clear error messages.

What next?

  • Introduce AccountId (in bourso_api) to solve primitive obsession properly. Implement FromStr and use it in CLI + API.

  • Split handlers into modules (small, testable functions):

    src/
    ├─ main.rs           # init + parse + call run()
    ├─ lib.rs            # run() dispatcher
    ├─ cli.rs            # clap structs (this PR)
    ├─ commands/         # accounts.rs, quote.rs, trade/, transfer.rs
    ├─ services/         # client.rs, auth.rs (MFA/login)
    └─ settings/         # as today
    

    Example target:

    pub async fn run(cli: cli::Cli) -> Result<()> {
        use cli::Commands::*;
        match cli.command {
            Config(args)   => commands::config::handle(args).await,
            Quote(args)    => commands::quote::handle(args).await,
            // ...
        }
    }

Mathious6 and others added 8 commits November 1, 2025 16:42
* chore: add devcontainer configuration for Rust development

* chore: format Cargo.toml files with `Even Better TOML`

* chore: add rust-toolchain configuration for stable channel with rustfmt and clippy

* chore: include custom container name

* chore: add GitHub Actions extension to devcontainer
* chore: migrate from log to tracing for logging, update dependencies, and clean up unused packages

* refactor: replace log with tracing for debug statements in transfer module

* refactor: reorganize module imports and enhance settings management

* refactor: remove redundant write operation in save_settings function

* refactor: replace log debug statements with tracing in transfer module

* refactor: remove tracing-appender dependency and simplify logger initialization

* chore: remove .devcontainer entry from .gitignore

* chore: update Cargo.toml formatting and enhance devcontainer configuration
@azerpas azerpas changed the base branch from main to 1.0 November 2, 2025 14:12
Copy link
Owner

@azerpas azerpas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a reason for which I didn't used derive at first, but I can't put my head around it... Anyway, awesome refactoring job once again, thanks Mathis :)

@azerpas azerpas merged commit e7ec1e3 into azerpas:1.0 Nov 8, 2025
1 check passed
@Mathious6 Mathious6 deleted the mathious6/refactor/cli-architecture branch November 8, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants