# Module BSV::Wallet::CLI <a id="module-BSV-Wallet-CLI"></a>

Shared boot sequence for CLI utilities.

Each bin/ tool runs in its own OS process, so the global Sequel::Model.db is
safe — only one wallet per process.

Two boot modes:

    * **End-user mode** (+wallet_name: nil+): single wallet, settings
      come from +BSV::Wallet.config+ (the +configure+ block in
      +~/.bsv-wallet/config.rb+, falling back to ENV defaults). See
      +lib/bsv/wallet/config.rb+ and +config/config.example.rb+.

    * **Dev/test mode** (+wallet_name: 'alice'+ etc.): named-wallet
      fixtures resolve through +BSV::Wallet::Fixtures+ (the
      +configure+ block in +~/.bsv-wallet/fixtures.rb+, falling
      back to the gem-bundled default which reads
      +BSV_WALLET_WIF_<NAME>+ / +DATABASE_URL_<NAME>+ /
      +BSV_WALLET_POSTGRES+ from shell ENV). See
      +lib/bsv/wallet/fixtures.rb+ and +config/fixtures.rb+.

**@example**
```ruby
wallet_name, args = BSV::Wallet::CLI.extract_wallet_name(ARGV)
ctx = BSV::Wallet::CLI.boot(wallet_name: wallet_name)
engine = ctx[:engine]
```

## Public Class Methods
### `boot(wallet_name: = nil, network: = nil, wif_override: = nil, database_url_override: = nil)` <a id="method-c-boot"></a> <a id="boot-class_method"></a>
Boot a wallet engine for the named wallet.

Auto-discovers the store backend, runs migrations, and constructs all Layer 2a
components + the Engine.
- **@param** `wallet_name` [String, nil] e.g. "alice", "bob", or nil for default
- **@param** `network` [Symbol, nil] :mainnet or :testnet; nil → read from config
- **@param** `wif_override` [String, nil] explicit WIF (from +--wif+ /
+--wif-file+); +nil+ → fall back to Fixtures / Config / ENV
- **@param** `database_url_override` [String, nil] explicit DB URL (from
+--database-url+); +nil+ → fall back to Fixtures / Config / ENV
- **@return** [Hash] { engine:, utxo_pool:, key_deriver:, db:, identity_key:, private_key: }

### `default_sqlite_url(wallet_name)` <a id="method-c-default_sqlite_url"></a> <a id="default_sqlite_url-class_method"></a>
Build the default SQLite URL when DATABASE_URL is unset.
- **@param** `wallet_name` [String, nil]
- **@return** [String]

### `extract_wallet_name(argv)` <a id="method-c-extract_wallet_name"></a> <a id="extract_wallet_name-class_method"></a>
Extract wallet name from the argument list.

The wallet name is the first argument if it matches a simple identifier
pattern (letters/digits/underscores, starts with a letter). Flags (--foo) and
hex strings (64-char txids) are not wallet names.
- **@param** `argv` [Array<String>]
- **@return** [Array(String, Array<String>)] [wallet_name_or_nil, remaining_args]

### `missing_wif_message(wallet_name)` <a id="method-c-missing_wif_message"></a> <a id="missing_wif_message-class_method"></a>
Context-aware error message for the missing-WIF abort.
- **@param** `wallet_name` [String, nil]
- **@return** [String]
