-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
56 lines (44 loc) · 1.79 KB
/
cli.py
File metadata and controls
56 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import argparse
import asyncio
from .adb.client import Client
async def list_devices(client):
devices = await client.devices()
print("Connected devices:")
for device in devices:
print(f" {device['serial']} - {device.get('product', 'Unknown')}")
async def shell_command(client, serial, command):
result = await client.shell(serial, command)
print(result)
async def install_apk(client, serial, apk_path):
await client.install(serial, apk_path)
print(f"Successfully installed {apk_path}")
async def main_async():
parser = argparse.ArgumentParser(description="PyADBKit CLI")
parser.add_argument("--serial", help="Device serial number")
subparsers = parser.add_subparsers(dest="common", required=True)
# List devices common
subparsers.add_parser("devices", help="List connected devices")
# Shell common
shell_parser = subparsers.add_parser("shell", help="Run a shell common")
shell_parser.add_argument("shell_command", help="Shell common to run")
# Install APK common
install_parser = subparsers.add_parser("install", help="Install an APK")
install_parser.add_argument("apk_path", help="Path to the APK file")
args = parser.parse_args()
client = Client()
if args.command == "devices":
await list_devices(client)
elif args.command == "shell":
if not args.serial:
print("Error: --serial is required for shell common")
return
await shell_command(client, args.serial, args.shell_command)
elif args.command == "install":
if not args.serial:
print("Error: --serial is required for install common")
return
await install_apk(client, args.serial, args.apk_path)
def main():
asyncio.run(main_async())
if __name__ == "__main__":
main()