Skip to content

Commit 29357cc

Browse files
committed
Support for short options for common ones.
Signed-off-by: Kevin Stanley <stanleyk@objectcomputing.com>
1 parent 2f9c29d commit 29357cc

5 files changed

Lines changed: 108 additions & 79 deletions

File tree

unityauth-cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ SELECT id, name, description FROM service WHERE status = 'ENABLED';
233233
## Documentation
234234

235235
- [User Guide](docs/user-guide.md) - Complete command reference
236-
- [Quickstart Guide](../specs/001-unityauth-cli/quickstart.md) - Detailed usage scenarios
237-
- [UnityAuth API](../CLAUDE.md) - Backend API reference
236+
237+
- [API Reference](docs/api-reference.md) - UnityAuth API documentation
238238

239239
## Development
240240

unityauth-cli/docs/user-guide.md

Lines changed: 97 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,28 @@ Complete command reference for the UnityAuth command-line interface.
3939

4040
These options are available for all commands:
4141

42-
| Option | Environment Variable | Description |
43-
|--------|---------------------|-------------|
44-
| `--api-url TEXT` | `UNITYAUTH_API_URL` | Override the API endpoint URL |
45-
| `--format [table\|json\|csv]` | - | Set output format (default: table) |
46-
| `--verbose` | - | Enable debug/verbose output |
47-
| `--version` | - | Show version and exit |
48-
| `--help` | - | Show help message and exit |
42+
| Option | Short | Environment Variable | Description |
43+
|--------|-------|---------------------|-------------|
44+
| `--api-url TEXT` | | `UNITYAUTH_API_URL` | Override the API endpoint URL |
45+
| `--format [table\|json\|csv]` | `-o` | - | Set output format (default: table) |
46+
| `--verbose` | `-v` | - | Enable debug/verbose output |
47+
| `--version` | | - | Show version and exit |
48+
| `--help` | | - | Show help message and exit |
4949

5050
**Examples:**
5151

5252
```bash
5353
# Override API URL for a single command
5454
unityauth --api-url https://staging.example.com tenant list
5555

56-
# Get JSON output
57-
unityauth --format json role list
56+
# Get JSON output (using short flag)
57+
unityauth -o json role list
58+
59+
# Enable verbose mode for debugging (using short flag)
60+
unityauth -v login
5861

59-
# Enable verbose mode for debugging
60-
unityauth --verbose login
62+
# Combine short flags
63+
unityauth -v -o json tenant list
6164
```
6265

6366
---
@@ -120,10 +123,10 @@ Password: ********
120123
Setup complete!
121124
122125
Next steps:
123-
$ unityauth tenant list # List your tenants
124-
$ unityauth user list --tenant-id 1 # List users in tenant 1
125-
$ unityauth role list # List available roles
126-
$ unityauth --help # See all commands
126+
$ unityauth tenant list # List your tenants
127+
$ unityauth user list -t 1 # List users in tenant 1
128+
$ unityauth role list # List available roles
129+
$ unityauth --help # See all commands
127130
```
128131

129132
**Exit Codes:**
@@ -235,7 +238,7 @@ unityauth token-info
235238
unityauth token-info
236239

237240
# JSON output for scripting
238-
unityauth token-info --format json
241+
unityauth token-info -o json
239242
```
240243

241244
---
@@ -320,14 +323,20 @@ unityauth user create [OPTIONS]
320323

321324
**Required Options:**
322325

323-
| Option | Description |
324-
|--------|-------------|
325-
| `--email TEXT` | User's email address (must be unique per tenant) |
326-
| `--first-name TEXT` | User's first name (1-100 characters) |
327-
| `--last-name TEXT` | User's last name (1-100 characters) |
328-
| `--password TEXT` | Initial password (minimum 8 characters) |
329-
| `--tenant-id INTEGER` | Tenant ID to assign the user to |
330-
| `--role-ids TEXT` | Comma-separated role IDs (e.g., "1,2,3") |
326+
| Option | Short | Description |
327+
|--------|-------|-------------|
328+
| `--email TEXT` | | User's email address (must be unique per tenant) |
329+
| `--first-name TEXT` | | User's first name (1-100 characters) |
330+
| `--last-name TEXT` | | User's last name (1-100 characters) |
331+
| `--password TEXT` | | Initial password (minimum 8 characters) |
332+
| `--tenant-id INTEGER` | `-t` | Tenant ID to assign the user to |
333+
| `--role-ids TEXT` | `-r` | Comma-separated role IDs (e.g., "1,2,3") |
334+
335+
**Optional Options:**
336+
337+
| Option | Short | Description |
338+
|--------|-------|-------------|
339+
| `--dry-run` | `-n` | Preview the user creation without actually creating |
331340

332341
**Required Permissions:**
333342

@@ -343,17 +352,24 @@ unityauth user create \
343352
--first-name John \
344353
--last-name Doe \
345354
--password "SecureP@ss123" \
346-
--tenant-id 1 \
347-
--role-ids 2
355+
-t 1 \
356+
-r 2
348357

349-
# Create a user with multiple roles
358+
# Create a user with multiple roles (using short flags)
350359
unityauth user create \
351360
--email admin@example.com \
352361
--first-name Jane \
353362
--last-name Admin \
354363
--password "AdminP@ss456" \
355-
--tenant-id 1 \
356-
--role-ids "1,2,3"
364+
-t 1 -r "1,2,3"
365+
366+
# Preview user creation without executing (dry run)
367+
unityauth user create --dry-run \
368+
--email user@example.com \
369+
--first-name John \
370+
--last-name Doe \
371+
--password "SecureP@ss123" \
372+
-t 1 -r 2
357373
```
358374

359375
**Common Errors:**
@@ -371,14 +387,14 @@ unityauth user create \
371387
List all users in a specific tenant.
372388

373389
```
374-
unityauth user list --tenant-id TENANT_ID
390+
unityauth user list -t TENANT_ID
375391
```
376392

377393
**Required Options:**
378394

379-
| Option | Description |
380-
|--------|-------------|
381-
| `--tenant-id INTEGER` | Tenant ID to list users from |
395+
| Option | Short | Description |
396+
|--------|-------|-------------|
397+
| `--tenant-id INTEGER` | `-t` | Tenant ID to list users from |
382398

383399
**Output Columns:**
384400

@@ -394,13 +410,13 @@ unityauth user list --tenant-id TENANT_ID
394410

395411
```bash
396412
# List users in tenant 1
397-
unityauth user list --tenant-id 1
413+
unityauth user list -t 1
398414

399-
# Get JSON output for scripting
400-
unityauth user list --tenant-id 1 --format json
415+
# Get JSON output for scripting (using short flags)
416+
unityauth user list -t 1 -o json
401417

402418
# Export to CSV
403-
unityauth user list --tenant-id 1 --format csv > users.csv
419+
unityauth user list -t 1 -o csv > users.csv
404420
```
405421

406422
---
@@ -410,7 +426,7 @@ unityauth user list --tenant-id 1 --format csv > users.csv
410426
Update role assignments for an existing user.
411427

412428
```
413-
unityauth user update USER_ID --tenant-id TENANT_ID --role-ids ROLE_IDS
429+
unityauth user update USER_ID -t TENANT_ID -r ROLE_IDS
414430
```
415431

416432
**Arguments:**
@@ -421,10 +437,16 @@ unityauth user update USER_ID --tenant-id TENANT_ID --role-ids ROLE_IDS
421437

422438
**Required Options:**
423439

424-
| Option | Description |
425-
|--------|-------------|
426-
| `--tenant-id INTEGER` | Tenant ID where roles are assigned |
427-
| `--role-ids TEXT` | Comma-separated role IDs to assign |
440+
| Option | Short | Description |
441+
|--------|-------|-------------|
442+
| `--tenant-id INTEGER` | `-t` | Tenant ID where roles are assigned |
443+
| `--role-ids TEXT` | `-r` | Comma-separated role IDs to assign |
444+
445+
**Optional Options:**
446+
447+
| Option | Short | Description |
448+
|--------|-------|-------------|
449+
| `--dry-run` | `-n` | Preview the role changes without actually updating |
428450

429451
**Behavior:**
430452

@@ -435,10 +457,13 @@ unityauth user update USER_ID --tenant-id TENANT_ID --role-ids ROLE_IDS
435457

436458
```bash
437459
# Update user 5's roles in tenant 1
438-
unityauth user update 5 --tenant-id 1 --role-ids "2,3"
460+
unityauth user update 5 -t 1 -r "2,3"
439461

440462
# Assign a single role
441-
unityauth user update 10 --tenant-id 1 --role-ids 2
463+
unityauth user update 10 -t 1 -r 2
464+
465+
# Preview role changes without executing (dry run)
466+
unityauth user update 5 --dry-run -t 1 -r "2,3"
442467
```
443468

444469
---
@@ -459,11 +484,12 @@ unityauth user update-profile USER_ID [OPTIONS]
459484

460485
**Options:**
461486

462-
| Option | Description |
463-
|--------|-------------|
464-
| `--first-name TEXT` | New first name (1-100 characters) |
465-
| `--last-name TEXT` | New last name (1-100 characters) |
466-
| `--password TEXT` | New password (minimum 8 characters) |
487+
| Option | Short | Description |
488+
|--------|-------|-------------|
489+
| `--first-name TEXT` | | New first name (1-100 characters) |
490+
| `--last-name TEXT` | | New last name (1-100 characters) |
491+
| `--password TEXT` | | New password (minimum 8 characters) |
492+
| `--dry-run` | `-n` | Preview the profile changes without actually updating |
467493

468494
**Behavior:**
469495

@@ -489,6 +515,9 @@ unityauth user update-profile 5 --password "NewSecureP@ss123"
489515

490516
# Update multiple fields at once
491517
unityauth user update-profile 5 --first-name John --last-name Smith --password "NewP@ss"
518+
519+
# Preview profile changes without executing (dry run)
520+
unityauth user update-profile 5 --dry-run --first-name John --last-name Smith
492521
```
493522

494523
**Common Errors:**
@@ -531,11 +560,11 @@ unityauth tenant list
531560
# List all accessible tenants
532561
unityauth tenant list
533562

534-
# Get JSON output
535-
unityauth tenant list --format json
563+
# Get JSON output (using short flag)
564+
unityauth tenant list -o json
536565

537566
# Get just tenant names using jq
538-
unityauth tenant list --format json | jq -r '.[].name'
567+
unityauth tenant list -o json | jq -r '.[].name'
539568
```
540569

541570
---
@@ -570,11 +599,11 @@ unityauth tenant users TENANT_ID
570599
# List users in tenant 1
571600
unityauth tenant users 1
572601

573-
# Get JSON output
574-
unityauth tenant users 1 --format json
602+
# Get JSON output (using short flag)
603+
unityauth tenant users 1 -o json
575604

576605
# Count users in a tenant
577-
unityauth tenant users 1 --format json | jq length
606+
unityauth tenant users 1 -o json | jq length
578607
```
579608

580609
---
@@ -603,11 +632,11 @@ unityauth role list
603632
# List all roles
604633
unityauth role list
605634

606-
# Get JSON output
607-
unityauth role list --format json
635+
# Get JSON output (using short flag)
636+
unityauth role list -o json
608637

609638
# Find a specific role ID
610-
unityauth role list --format json | jq '.[] | select(.name == "Tenant Administrator")'
639+
unityauth role list -o json | jq '.[] | select(.name == "Tenant Administrator")'
611640
```
612641

613642
---
@@ -619,15 +648,15 @@ unityauth role list --format json | jq '.[] | select(.name == "Tenant Administra
619648
List your permissions for a specific tenant and service.
620649

621650
```
622-
unityauth permissions list --tenant-id TENANT_ID --service-id SERVICE_ID
651+
unityauth permissions list -t TENANT_ID -s SERVICE_ID
623652
```
624653

625654
**Required Options:**
626655

627-
| Option | Description |
628-
|--------|-------------|
629-
| `--tenant-id INTEGER` | Tenant ID to check permissions for |
630-
| `--service-id INTEGER` | Service ID to check permissions for |
656+
| Option | Short | Description |
657+
|--------|-------|-------------|
658+
| `--tenant-id INTEGER` | `-t` | Tenant ID to check permissions for |
659+
| `--service-id INTEGER` | `-s` | Service ID to check permissions for |
631660

632661
**Output:**
633662

@@ -637,13 +666,13 @@ Returns all permissions the authenticated user has for the specified tenant and
637666

638667
```bash
639668
# List your permissions for tenant 1 and Libre311 service (ID: 1)
640-
unityauth permissions list --tenant-id 1 --service-id 1
669+
unityauth permissions list -t 1 -s 1
641670

642-
# Get JSON output
643-
unityauth permissions list --tenant-id 1 --service-id 1 --format json
671+
# Get JSON output (using short flags)
672+
unityauth permissions list -t 1 -s 1 -o json
644673

645674
# Get CSV output
646-
unityauth permissions list --tenant-id 1 --service-id 1 --format csv
675+
unityauth permissions list -t 1 -s 1 -o csv
647676
```
648677

649678
**Sample Output:**
@@ -790,7 +819,7 @@ export UNITYAUTH_PASSWORD="$ADMIN_PASSWORD"
790819
unityauth login
791820

792821
# Perform operations
793-
unityauth user list --tenant-id 1 --format json > users.json
822+
unityauth user list -t 1 -o json > users.json
794823

795824
# Cleanup
796825
unityauth logout

unityauth-cli/src/unityauth_cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ def wrapper(ctx: CLIContext, *args, **kwargs):
123123
help='UnityAuth API endpoint URL (overrides config file)',
124124
)
125125
@click.option(
126-
'--format',
126+
'-o', '--format',
127127
'output_format',
128128
type=click.Choice(['table', 'json', 'csv'], case_sensitive=False),
129129
help='Output format (default: table)',
130130
)
131131
@click.option(
132-
'--verbose',
132+
'-v', '--verbose',
133133
is_flag=True,
134134
help='Enable verbose/debug output',
135135
)

unityauth-cli/src/unityauth_cli/commands/permissions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727

2828
@click.command('list')
29-
@click.option('--tenant-id', required=True, type=int, help='Tenant ID to check permissions for')
30-
@click.option('--service-id', required=True, type=int, help='Service ID to check permissions for')
29+
@click.option('-t', '--tenant-id', required=True, type=int, help='Tenant ID to check permissions for')
30+
@click.option('-s', '--service-id', required=True, type=int, help='Service ID to check permissions for')
3131
@pass_context
3232
@require_auth
3333
def list_permissions(

unityauth-cli/src/unityauth_cli/commands/users.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
@click.option('--first-name', required=True, help='User first name')
3232
@click.option('--last-name', required=True, help='User last name')
3333
@click.option('--password', required=True, help='User password (min 8 characters)')
34-
@click.option('--tenant-id', required=True, type=int, help='Tenant ID for the user')
35-
@click.option('--role-ids', required=True, help='Comma-separated role IDs (e.g., "1,2,3")')
34+
@click.option('-t', '--tenant-id', required=True, type=int, help='Tenant ID for the user')
35+
@click.option('-r', '--role-ids', required=True, help='Comma-separated role IDs (e.g., "1,2,3")')
3636
@click.option('--dry-run', '-n', is_flag=True, help='Preview changes without executing')
3737
@pass_context
3838
@require_auth
@@ -153,8 +153,8 @@ def create(
153153

154154
@click.command()
155155
@click.argument('user_id', type=int)
156-
@click.option('--tenant-id', required=True, type=int, help='Tenant ID where user has roles')
157-
@click.option('--role-ids', required=True, help='Comma-separated role IDs to assign (e.g., "1,2,3")')
156+
@click.option('-t', '--tenant-id', required=True, type=int, help='Tenant ID where user has roles')
157+
@click.option('-r', '--role-ids', required=True, help='Comma-separated role IDs to assign (e.g., "1,2,3")')
158158
@click.option('--dry-run', '-n', is_flag=True, help='Preview changes without executing')
159159
@pass_context
160160
@require_auth
@@ -331,7 +331,7 @@ def update_profile(
331331

332332

333333
@click.command()
334-
@click.option('--tenant-id', type=int, required=True, help='Tenant ID to list users from')
334+
@click.option('-t', '--tenant-id', type=int, required=True, help='Tenant ID to list users from')
335335
@pass_context
336336
@require_auth
337337
def list_users(ctx: CLIContext, tenant_id: int, client: UnityAuthAPIClient) -> None:

0 commit comments

Comments
 (0)