Skip to content

Commit b2388c1

Browse files
toratoraMark Knasiakaluedekegbalduzzi
authored
Have 'diskspace', 'tunnel ls', and 'devmode get' output unformatted JSON (#672)
* Have 'diskspace', 'tunnel ls', and 'devmode' output unformatted JSON without --nojson flag remove extranous nil check before exitIfError * feat: Additional fields to batteryregistry * fix: proper parsing of locale and lang arguments in prepare command * feat: Added skip keys new to iOS 26 * Have 'diskspace', 'tunnel ls', and 'devmode' output unformatted JSON without --nojson flag remove extranous nil check before exitIfError --------- Co-authored-by: Mark Knasiak <[email protected]> Co-authored-by: Andreas Lüdeke <[email protected]> Co-authored-by: Giorgio Balduzzi <[email protected]>
1 parent 82e1a15 commit b2388c1

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

main.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,14 +1534,16 @@ The commands work as following:
15341534
afcService, err := afc.New(device)
15351535
exitIfError("connect afc service failed", err)
15361536
info, err := afcService.DeviceInfo()
1537-
if err != nil {
1538-
exitIfError("get device info push failed", err)
1537+
exitIfError("get device info push failed", err)
1538+
if JSONdisabled {
1539+
fmt.Printf(" Model: %s\n", info.Model)
1540+
fmt.Printf(" BlockSize: %d\n", info.BlockSize)
1541+
fmt.Printf(" FreeSpace: %s\n", ios.ByteCountDecimal(int64(info.FreeBytes)))
1542+
fmt.Printf(" UsedSpace: %s\n", ios.ByteCountDecimal(int64(info.TotalBytes-info.FreeBytes)))
1543+
fmt.Printf(" TotalSpace: %s\n", ios.ByteCountDecimal(int64(info.TotalBytes)))
1544+
} else {
1545+
fmt.Println(convertToJSONString(info))
15391546
}
1540-
fmt.Printf(" Model: %s\n", info.Model)
1541-
fmt.Printf(" BlockSize: %d\n", info.BlockSize)
1542-
fmt.Printf(" FreeSpace: %s\n", ios.ByteCountDecimal(int64(info.FreeBytes)))
1543-
fmt.Printf(" UsedSpace: %s\n", ios.ByteCountDecimal(int64(info.TotalBytes-info.FreeBytes)))
1544-
fmt.Printf(" TotalSpace: %s\n", ios.ByteCountDecimal(int64(info.TotalBytes)))
15451547
return
15461548
}
15471549

@@ -1556,9 +1558,7 @@ The commands work as following:
15561558
useUserspaceNetworking, _ := arguments.Bool("--userspace")
15571559
if startCommand && !useUserspaceNetworking {
15581560
err := ios.CheckRoot()
1559-
if err != nil {
1560-
exitIfError("If --userspace is not set, we need sudo or an admin shell on Windows", err)
1561-
}
1561+
exitIfError("If --userspace is not set, we need sudo or an admin shell on Windows", err)
15621562
}
15631563
if useUserspaceNetworking {
15641564
log.Info("Using userspace networking")
@@ -1576,12 +1576,18 @@ The commands work as following:
15761576
startTunnel(context.TODO(), pairRecordsPath, tunnelInfoPort, useUserspaceNetworking)
15771577
} else if listCommand {
15781578
tunnels, err := tunnel.ListRunningTunnels(tunnelInfoHost, tunnelInfoPort)
1579-
if err != nil {
1580-
exitIfError("failed to get tunnel infos", err)
1579+
exitIfError("failed to get tunnel infos", err)
1580+
if disableJSON {
1581+
for index, t := range tunnels {
1582+
if 0 != index {
1583+
fmt.Println()
1584+
}
1585+
fmt.Printf("Udid: %s\n Address: %s\n RsdPort: %d\n UserspaceTUN: %v\n UserspaceTUNPort: %d\n",
1586+
t.Udid, t.Address, t.RsdPort, t.UserspaceTUN, t.UserspaceTUNPort)
1587+
}
1588+
} else {
1589+
fmt.Println(convertToJSONString(tunnels))
15811590
}
1582-
enc := json.NewEncoder(os.Stdout)
1583-
enc.SetIndent("", " ")
1584-
_ = enc.Encode(tunnels)
15851591
}
15861592
if stopagent {
15871593
err := tunnel.CloseAgent()
@@ -1604,7 +1610,12 @@ The commands work as following:
16041610

16051611
if get {
16061612
devModeEnabled, _ := imagemounter.IsDevModeEnabled(device)
1607-
fmt.Printf("Developer mode enabled: %v\n", devModeEnabled)
1613+
if JSONdisabled {
1614+
fmt.Printf("Developer mode enabled: %v\n", devModeEnabled)
1615+
} else {
1616+
result := map[string]interface{}{"DeveloperModeEnabled": devModeEnabled}
1617+
fmt.Println(convertToJSONString(result))
1618+
}
16081619
}
16091620

16101621
return

0 commit comments

Comments
 (0)