Skip to content

Commit

Permalink
Merge pull request #11 from rcpirate/master
Browse files Browse the repository at this point in the history
add color/no-color option, control print_json
  • Loading branch information
codeskyblue authored Apr 29, 2024
2 parents d686f9e + 8ee20e0 commit 7f2d185
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions tidevice3/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ def app_kill(service_provider, pid: int):

@app.command("ps")
@click.option('--json/--no-json', default=False)
@click.option("--color/--no-color", default=True, help="print colord")
@pass_rsd
def app_ps(service_provider: LockdownClient, json: bool):
def app_ps(service_provider: LockdownClient, json: bool, color: bool):
"""list running processes"""
if service_provider.product_version < "17":
logger.warning('iOS<17 have FD leak, which will cause an error when calling round more than 250 times.')
processes = list(proclist(service_provider))
processes = [p.model_dump(exclude_none=True) for p in processes if p.isApplication]
if json:
print_json(processes)
print_json(processes, color)
else:
print_dict_as_table(processes, ["pid", "name", "bundleIdentifier", "realAppName"])

Expand All @@ -123,8 +124,9 @@ def app_foreground(service_provider: LockdownClient):

@app.command("info")
@click.argument("bundle_identifier")
@click.option("--color/--no-color", default=True, help="print colord")
@pass_rsd
def app_info(service_provider: LockdownClient, bundle_identifier: str):
def app_info(service_provider: LockdownClient, bundle_identifier: str, color: bool):
with InstallationProxyService(lockdown=service_provider) as iproxy:
apps = iproxy.get_apps(bundle_identifiers=[bundle_identifier])
print_json(apps)
print_json(apps, color)
6 changes: 4 additions & 2 deletions tidevice3/cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Created on Tue Feb 27 2024 10:38:24 by codeskyblue
"""
import click

from pymobiledevice3.cli.cli_common import print_json
from pymobiledevice3.lockdown import LockdownClient
Expand All @@ -11,8 +12,9 @@


@cli.command("info")
@click.option("--color/--no-color", default=True, help="print colord")
@pass_service_provider
def info(service_provider: LockdownClient):
def info(service_provider: LockdownClient, color: bool):
""" print device info """
print_json(service_provider.short_info)
print_json(service_provider.short_info, color)

5 changes: 3 additions & 2 deletions tidevice3/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
@click.option("-u", "--usb", is_flag=True, help="show only usb devices")
@click.option("-n", "--network", is_flag=True, help="show only network devices")
@click.option("--json", is_flag=True, help="output as json format")
@click.option("--color/--no-color", default=True, help="print colord")
@click.pass_context
def cli_list(ctx: click.Context, usb: bool, network: bool, json: bool):
def cli_list(ctx: click.Context, usb: bool, network: bool, json: bool, color: bool):
"""list connected devices"""
usbmux_address = ctx.obj["usbmux_address"]
devices = list_devices(usb, network, usbmux_address)
if json:
print_json([d.model_dump() for d in devices])
print_json([d.model_dump() for d in devices], color)
else:
headers = ["Identifier", "DeviceName", "ProductType", "ProductVersion", "ConnectionType"]
print_dict_as_table([d.model_dump() for d in devices], headers)
Expand Down

0 comments on commit 7f2d185

Please sign in to comment.