Skip to content

Replace custom validators with Click primitives#1155

Merged
anderdc merged 3 commits into
entrius:testfrom
seroperson:reuse-click-conditions
May 13, 2026
Merged

Replace custom validators with Click primitives#1155
anderdc merged 3 commits into
entrius:testfrom
seroperson:reuse-click-conditions

Conversation

@seroperson
Copy link
Copy Markdown
Contributor

@seroperson seroperson commented May 11, 2026

Closes #1154

Summary

Replaces a layer of parameter-validation helpers across the CLI with Click's built-in primitives.

  • validate_issue_id / require_valid_issue_id replaced with ContractIssueType Click param type.
  • validate_ss58_address / require_valid_ss58 replaced with SS58AddressType Click param type.
  • GitHub-issue-number parameters now has GitHubIssueType Click param type.
  • RepoNameType - for --repo parameter, checks "owner/repo" string against REPO_PATTERN.
  • --network gets type=NETWORK_CHOICE (the existing click.Choice(['finney','test','local']), so invalid networks fail at parse instead of at subtensor connect time.
  • --pat gets envvar='GITTENSOR_MINER_PAT', the body-level os.environ.get(...) fallback is deleted.

Behavior change worth flagging: gitt i list --json --id 0 and gitt i submissions --json --id 0 no longer emit a JSON envelope on bad id, but it already covered by #1152 (which makes --json handle Click's exceptions).

How it looks like

User-visible error-message changes (sample, captured via Click test runner):

$ gitt i list --id 0
Usage: cli i list [OPTIONS]
Try 'cli i list --help' for help.

Error: Invalid value for '--id': 0 is not in the range 1<=x<=999999.

$ gitt admin set-owner not-an-ss58
Usage: cli admin set-owner [OPTIONS] NEW_OWNER
Try 'cli admin set-owner --help' for help.

Error: Invalid value for new_owner: Invalid SS58 address for new_owner: not-an-ss58

$ gitt miner post --network mainnet
Usage: cli miner post [OPTIONS]
Try 'cli miner post --help' for help.

Error: Invalid value for '--network': 'mainnet' is not one of 'finney', 'test', 'local'.

--help excerpts (auto-generated by Click from IntRange / Choice):

--id INTEGER RANGE     View a specific issue by ID  [1<=x<=999999]
--network [finney|test|local]
--pat TEXT             ... [env: GITTENSOR_MINER_PAT]

Testing

Dropped several basic tests which check issue_id parameter + dropped test which checks that incorrect issue_id parameter makes CLI response with a specific error format when used with --json (covered in #1152)

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label May 11, 2026
@seroperson seroperson force-pushed the reuse-click-conditions branch from 4d0ddd0 to 9281032 Compare May 11, 2026 15:11
@anderdc anderdc merged commit 0f442df into entrius:test May 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace custom validators with Click primitives

2 participants