Skip to content

Commit fe6e08e

Browse files
authored
Merge pull request #23 from kaincenteno/cli-annotated-help
docs(cli): improve cli documentation and add type hints
2 parents 1dca92b + 008ede1 commit fe6e08e

File tree

3 files changed

+171
-24
lines changed

3 files changed

+171
-24
lines changed

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,9 @@ The token path is the location where the access token will be stored.
3939
`pip install pyaxm`
4040

4141
## CLI:
42-
Usage: pyaxm-cli COMMAND [ARGS]
42+
A command-line interface (CLI) tool called `pyaxm-cli` is included for easy access to the API.
4343

44-
### Commands
45-
`devices` -> List all devices in the organization.
46-
47-
`device` -> Get a device by ID.
48-
49-
`mdm-servers` -> List all MDM servers.
50-
51-
`mdm-server` -> List devices in a specific MDM server.
52-
53-
`mdm-server-assigned` -> Get the server assignment for a device.
54-
55-
`assign-device` -> Assign a device to an MDM server.
56-
57-
`unassign-device` -> Unassign a device from an MDM server.
58-
59-
`apple-care-coverage` -> Get AppleCare warranty coverage information for a device.
60-
The data returned is on CSV format so you can store it as a CSV if needed
44+
For detailed usage instructions, available commands, options, and examples, please refer to the [CLI documentation](docs/cli.md).
6145

6246
# Client:
6347
Example usage:

docs/cli.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# `pyaxm-cli`
2+
3+
**Usage**:
4+
5+
```console
6+
$ pyaxm-cli [OPTIONS] COMMAND [ARGS]...
7+
```
8+
9+
**Options**:
10+
11+
* `--install-completion`: Install completion for the current shell.
12+
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
13+
* `--help`: Show this message and exit.
14+
15+
**Commands**:
16+
17+
* `devices`: List all devices in the organization.
18+
* `device`: Get a device by ID.
19+
* `apple-care-coverage`: Get AppleCare coverage for a device.
20+
* `mdm-servers`: List all MDM servers.
21+
* `mdm-server`: List devices in a specific MDM server.
22+
* `mdm-server-assigned`: Get the server assignment for a device.
23+
* `assign-device`: Assign one or more devices to an MDM server.
24+
* `unassign-device`: Unassign one or more devices from an MDM...
25+
26+
## `pyaxm-cli devices`
27+
28+
List all devices in the organization.
29+
30+
**Usage**:
31+
32+
```console
33+
$ pyaxm-cli devices [OPTIONS]
34+
```
35+
36+
**Options**:
37+
38+
* `--help`: Show this message and exit.
39+
40+
## `pyaxm-cli device`
41+
42+
Get a device by ID.
43+
44+
**Usage**:
45+
46+
```console
47+
$ pyaxm-cli device [OPTIONS] DEVICE_ID
48+
```
49+
50+
**Arguments**:
51+
52+
* `DEVICE_ID`: [required]
53+
54+
**Options**:
55+
56+
* `--help`: Show this message and exit.
57+
58+
## `pyaxm-cli apple-care-coverage`
59+
60+
Get AppleCare coverage for a device.
61+
62+
**Usage**:
63+
64+
```console
65+
$ pyaxm-cli apple-care-coverage [OPTIONS] DEVICE_ID
66+
```
67+
68+
**Arguments**:
69+
70+
* `DEVICE_ID`: [required]
71+
72+
**Options**:
73+
74+
* `--help`: Show this message and exit.
75+
76+
## `pyaxm-cli mdm-servers`
77+
78+
List all MDM servers.
79+
80+
**Usage**:
81+
82+
```console
83+
$ pyaxm-cli mdm-servers [OPTIONS]
84+
```
85+
86+
**Options**:
87+
88+
* `--help`: Show this message and exit.
89+
90+
## `pyaxm-cli mdm-server`
91+
92+
List devices in a specific MDM server.
93+
94+
**Usage**:
95+
96+
```console
97+
$ pyaxm-cli mdm-server [OPTIONS] SERVER_ID
98+
```
99+
100+
**Arguments**:
101+
102+
* `SERVER_ID`: [required]
103+
104+
**Options**:
105+
106+
* `--help`: Show this message and exit.
107+
108+
## `pyaxm-cli mdm-server-assigned`
109+
110+
Get the server assignment for a device.
111+
112+
**Usage**:
113+
114+
```console
115+
$ pyaxm-cli mdm-server-assigned [OPTIONS] DEVICE_ID
116+
```
117+
118+
**Arguments**:
119+
120+
* `DEVICE_ID`: [required]
121+
122+
**Options**:
123+
124+
* `--help`: Show this message and exit.
125+
126+
## `pyaxm-cli assign-device`
127+
128+
Assign one or more devices to an MDM server.
129+
130+
**Usage**:
131+
132+
```console
133+
$ pyaxm-cli assign-device [OPTIONS] DEVICE_ID... SERVER_ID
134+
```
135+
136+
**Arguments**:
137+
138+
* `DEVICE_ID...`: [required]
139+
* `SERVER_ID`: [required]
140+
141+
**Options**:
142+
143+
* `--help`: Show this message and exit.
144+
145+
## `pyaxm-cli unassign-device`
146+
147+
Unassign one or more devices from an MDM server.
148+
149+
**Usage**:
150+
151+
```console
152+
$ pyaxm-cli unassign-device [OPTIONS] DEVICE_ID... SERVER_ID
153+
```
154+
155+
**Arguments**:
156+
157+
* `DEVICE_ID...`: [required]
158+
* `SERVER_ID`: [required]
159+
160+
**Options**:
161+
162+
* `--help`: Show this message and exit.

pyaxm/cli.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import pandas as pd
33
import typer
4+
from typing_extensions import Annotated
45
from typing import List
56
from pyaxm.client import Client
67

@@ -20,7 +21,7 @@ def devices():
2021
df.to_csv(sys.stdout, index=False)
2122

2223
@app.command()
23-
def device(device_id: str):
24+
def device(device_id: Annotated[str, typer.Argument()]):
2425
"""Get a device by ID."""
2526
device = client.get_device(device_id)
2627
device_info = {'id': device.id}
@@ -29,7 +30,7 @@ def device(device_id: str):
2930
df.to_csv(sys.stdout, index=False)
3031

3132
@app.command()
32-
def apple_care_coverage(device_id: str):
33+
def apple_care_coverage(device_id: Annotated[str, typer.Argument()]):
3334
"""Get AppleCare coverage for a device."""
3435
coverage = client.get_apple_care_coverage(device_id)
3536
coverage_data = [item.attributes.model_dump() for item in coverage]
@@ -49,23 +50,23 @@ def mdm_servers():
4950
df.to_csv(sys.stdout, index=False)
5051

5152
@app.command()
52-
def mdm_server(server_id: str):
53+
def mdm_server(server_id: Annotated[str, typer.Argument()]):
5354
"""List devices in a specific MDM server."""
5455
devices = client.list_devices_in_mdm_server(server_id)
5556
devices_data = [{'id': device.id} for device in devices]
5657
df = pd.DataFrame(devices_data)
5758
df.to_csv(sys.stdout, index=False)
5859

5960
@app.command()
60-
def mdm_server_assigned(device_id: str):
61+
def mdm_server_assigned(device_id: Annotated[str, typer.Argument()]):
6162
"""Get the server assignment for a device."""
6263
server_assignment = client.get_device_server_assignment(device_id)
6364
assignment_info = {'id': server_assignment.id}
6465
df = pd.DataFrame([assignment_info])
6566
df.to_csv(sys.stdout, index=False)
6667

6768
@app.command()
68-
def assign_device(device_id: List[str], server_id: str):
69+
def assign_device(device_id: Annotated[List[str], typer.Argument()], server_id: Annotated[str, typer.Argument()]):
6970
"""Assign one or more devices to an MDM server."""
7071
activity = client.assign_unassign_device_to_mdm_server(device_id, server_id, 'ASSIGN_DEVICES')
7172
activity_data = {'id': activity.id}
@@ -74,7 +75,7 @@ def assign_device(device_id: List[str], server_id: str):
7475
df.to_csv(sys.stdout, index=False)
7576

7677
@app.command()
77-
def unassign_device(device_id: List[str], server_id: str):
78+
def unassign_device(device_id: Annotated[List[str], typer.Argument()], server_id: Annotated[str, typer.Argument()]):
7879
"""Unassign one or more devices from an MDM server."""
7980
activity = client.assign_unassign_device_to_mdm_server(device_id, server_id, 'UNASSIGN_DEVICES')
8081
activity_data = {'id': activity.id}

0 commit comments

Comments
 (0)