Skip to content

feat(cli): allow org credential options anywhere in the command#35

Open
buckleypaul wants to merge 1 commit into
mainfrom
feat/org-creds-anywhere
Open

feat(cli): allow org credential options anywhere in the command#35
buckleypaul wants to merge 1 commit into
mainfrom
feat/org-creds-anywhere

Conversation

@buckleypaul

Copy link
Copy Markdown
Collaborator

Summary

The org group's --org-id/-o and --token/-t had to be placed immediately after org (before the subcommand), because Click parses group-level options before the subcommand name. This makes them positionable anywhere in org commands, so the following now works:

hubblenetwork org register-device -e AES-128-EAX -c DEVICE_UPTIME -o MY_ORG_ID -t MY_TOKEN

Changes

  • Add _CredAnywhereGroup(click.Group), which hoists --org-id/-o and --token/-t (and their attached/=/space-separated values) to the front of the argument list before parsing. Credentials now work both before and after the subcommand and its options — no breaking change to the old position.
  • Rebind org get-packets's output-format flag from -o to -f, since -o is now reserved for --org-id across the whole org group. (--format long form is unchanged.)

Note: minor breaking change

org get-packets DEVICE -o json → use org get-packets DEVICE -f json (or --format json). -o on get-packets now means org-id.

Testing

  • New tests/test_org_option_position.py covers creds before/after/interspersed with the subcommand, --org-id=/--token= forms, space-separated long forms, and -o (org-id) / -f (format) coexistence on get-packets.
  • Full non-integration suite passes; ruff check src clean.

The org group's --org-id/-o and --token/-t had to precede the subcommand
because Click parses group options before the subcommand name. Add a
custom Group (_CredAnywhereGroup) that hoists these options (and their
values) to the front of the argument list before parsing, so they can
appear before or after the subcommand and its options, e.g.:

  hubblenetwork org register-device -e AES-128-EAX -o ORG -t TOKEN

Rebind `org get-packets` output-format flag from -o to -f, since -o is
now reserved for --org-id group-wide.
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.

1 participant