Skip to content

Commit

Permalink
add device list cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Sep 18, 2019
1 parent 99aec82 commit ef7319e
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -26,3 +26,4 @@ System
usr
*.bndb
.vscode/settings.json
xcode/data
10 changes: 10 additions & 0 deletions NOTES.md
@@ -0,0 +1,10 @@
# NOTES

## Misc

To get `github.com/mattn/go-sqlite3` golang dep

``` bash
$ export CGO_ENABLED=1; export CC=gcc; go get -v -x github.com/mattn/go-sqlite3
```

95 changes: 95 additions & 0 deletions cmd/ipsw/cmd/device_list.go
@@ -0,0 +1,95 @@
// +build cgo darwin

/*
Copyright © 2019 blacktop
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
"os"
"strconv"
"strings"

"github.com/blacktop/ipsw/xcode"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)

func init() {
deviceCmd.AddCommand(listCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
listCmd.Flags().BoolP("gen", "", false, "Generate device_traits.json file")
}

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all iOS devices",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {

gen, _ := cmd.Flags().GetBool("gen")
if gen {
devices, err := xcode.ReadDeviceTraitsDB()
if err != nil {
return err
}

err = xcode.WriteToJSON(devices)
if err != nil {
return err
}

return nil
}

devices, err := xcode.GetDevices()
if err != nil {
return err
}

data := [][]string{}
for _, device := range devices {
data = append(data, []string{
device.ProductType,
strings.Replace(device.ProductDescription, "generation", "gen", 1),
device.DeviceTrait.PreferredArchitecture,
strconv.Itoa(device.DeviceTrait.DevicePerformanceMemoryClass),
})
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Product", "Description", "Architecture", "Memory(GB)"})
table.AppendBulk(data)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.Render() // Send output

return nil
},
}
4 changes: 4 additions & 0 deletions go.mod
Expand Up @@ -8,9 +8,13 @@ require (
github.com/blacktop/lzss v0.1.0
github.com/hashicorp/go-version v1.2.0
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
github.com/jinzhu/gorm v1.9.10
github.com/kr/pty v1.1.8 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mattn/go-sqlite3 v1.11.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.1
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/pkg/errors v0.8.1
github.com/rakyll/statik v0.1.6
Expand Down

0 comments on commit ef7319e

Please sign in to comment.