Draft: Add account name validation parser to CLI
Problem
CLI shows raw validation error instead of user-friendly message:
$ clive process transfer --to a --amount 1hbd --no-broadcast
Unhandled exception ValidationError: Expected `str` of length >= 3
Solution
Added account_name() parser in parsers.py that:
- Uses existing
AccountNameValidatorfrom TUI - Shows friendly error message via
humanize_validation_result() - Is applied to ALL places where account name is accepted
Changes
Added account_name parser in parsers.py
def account_name(raw: str) -> str:
status = AccountNameValidator().validate(raw)
if status.is_valid:
return raw
raise typer.BadParameter(humanize_validation_result(status))
Applied parser to (16 files total):
Common templates (automatic coverage for many commands):
-
arguments.py: working_account_template -
options.py: working_account_template, working_account_list_template, new_account_name -
argument_related_options.py:--nameoption forclive show witness --name <witness_name>
Direct parameter usage:
-
process/main.py: transfer --to, change-recovery-account --new-recovery-account -
process/proxy.py: proxy set --proxy -
process/vote_witness.py: vote-witness add/remove --witness-name -
process/custom_operations/custom_json.py: custom-json --authorize-by-active -
process/update_authority.py: update-*-authority add-account/remove-account/modify-account --account -
process/hive_power/delegations.py: delegations set/remove --delegatee -
configure/profile.py: profile create --working-account-name -
configure/working_account.py: working-account switch -
configure/tracked_account.py: tracked-account add/remove -
configure/known_account.py: known-account add/remove -
generate/main.py: generate key-from-seed -
show/main.py: show witness / --name
Added unit tests
-
tests/unit/cli/test_parsers.py- tests for account_name parser:- Valid account names (alice, bob, gtg, etc.)
- Invalid account names (too short, special characters, uppercase, etc.)
- User-friendly error messages (no raw ValidationError)
- PERFORM_WORKING_ACCOUNT_LOAD placeholder passthrough
Result
Before:
Unhandled exception ValidationError: Expected `str` of length >= 3
After:
Invalid value for '--to': Invalid account name
Testing
Validation works for all commands accepting account name:
clive process transfer --to <invalid>clive process savings deposit --from <invalid> --to <invalid>clive process vote-witness add --witness-name <invalid>clive process delegations set --delegatee <invalid>clive configure tracked-account add <invalid>clive show balances <invalid>clive show witness --name <invalid>- etc.
Closes #484
Edited by Aleksandra Grabowska