Skip to content

fix(cli): persist selected network and use as default across invocations (closes #10) - #17

Open
ghzhost wants to merge 1 commit into
Txio-labs:mainfrom
ghzhost:fix/persist-selected-network
Open

fix(cli): persist selected network and use as default across invocations (closes #10)#17
ghzhost wants to merge 1 commit into
Txio-labs:mainfrom
ghzhost:fix/persist-selected-network

Conversation

@ghzhost

@ghzhost ghzhost commented Aug 17, 2026

Copy link
Copy Markdown

Summary

Persists the selected network (via Commands::Switch or disk storage) so subsequent commands default to the previously chosen network rather than silently resetting to Mainnet on every invocation.

Changes

  • Utils (src/utils/mod.rs):
    • Added save_current_network / save_network and get_current_network to persist/load network preference from ~/.txio/current_network mirroring the existing current_chain mechanism.
  • Parser (src/cli/parser.rs):
    • Made the global --network flag optional (Option<Network>) so CLI invocations can distinguish between explicitly passing a network and omitting it to fall back to the persisted setting.
    • Implemented FromStr for Network.
    • Updated Commands::Switch to accept optional chain: Option<String> and optional --network flag (network: Option<Network>).
  • Handlers (src/cli/handlers.rs):
    • Added CommandHandler::resolve_network(explicit_network: Option<Network>) -> Network implementing the precedence:
      1. Explicit --network flag (if provided).
      2. Persisted network in ~/.txio/current_network (if present and valid).
      3. Default fallback to Network::Mainnet.
    • Updated Commands::Switch to persist network when --network is supplied, along with chain switching.
    • Updated Commands::Status and all chain command adapters (Sui, Ethereum, Solana, Aptos, Soroban) to use the effective network.
  • Unit Tests:
    • Added test coverage in src/utils/mod.rs for network persistence round-trip.
    • Added test coverage in src/cli/handlers.rs for resolve_network precedence (first run default, persisted setting, and explicit override).

Closes #10

@Kingvic300

Copy link
Copy Markdown
Contributor

@ghzhost kindly resolve conflicts

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.

--network flag is never persisted, so chain commands silently default to Mainnet unless passed every invocation

2 participants