Skip to content

Commit

Permalink
make BaseDevice struct accessible to directory template (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj123 committed Sep 12, 2018
1 parent 9fc0762 commit 03b1dfb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Usage of ./allthefirmwares:
-c just check the integrity of the currently downloaded files (if any)
-d string
the location to save/check IPSW files.
Can include templates e.g. {{.Identifier}} or {{.BuildID}} (default "./")
Can include templates e.g. {{.Identifier}} or {{.Name}} or {{.BuildID}}
For example try -d "{{.Name}}/{{.Version}}"
(default "./")
-filter string
filter by a specific struct field
-filterValue string
Expand Down
19 changes: 11 additions & 8 deletions allthefirmwares.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
flag.BoolVar(&verifyIntegrity, "c", false, "just check the integrity of the currently downloaded files (if any)")
flag.BoolVar(&reDownloadOnVerificationFailed, "r", false, "redownload the file if it fails verification (w/ -c)")
flag.BoolVar(&downloadSigned, "s", false, "only download signed firmwares")
flag.StringVar(&downloadDirectoryTemplate, "d", "./", "the location to save/check IPSW files.\n\tCan include templates e.g. {{.Identifier}} or {{.BuildID}}")
flag.StringVar(&downloadDirectoryTemplate, "d", "./", "the location to save/check IPSW files.\n\tCan include templates e.g. {{.Identifier}} or {{.Name}} or {{.BuildID}}\n\n\tFor example try -d \"{{.Name}}/{{.Version}}\"\n")
flag.StringVar(&specifiedDevice, "i", "", "only download for the specified device")
flag.StringVar(&filter, "filter", "", "filter by a specific struct field")
flag.StringVar(&filterValue, "filterValue", "", "the value to filter by (used with -filter)")
Expand Down Expand Up @@ -100,7 +100,7 @@ func main() {
continue
}

directory, err := parseDownloadDirectory(&ipsw, device.Identifier)
directory, err := parseDownloadDirectory(&ipsw, &device)

if err != nil {
log.Printf("Unable to parse download directory, err: %s", err)
Expand Down Expand Up @@ -138,7 +138,7 @@ func main() {

filename := filepath.Base(ipsw.URL)

directory, err := parseDownloadDirectory(&ipsw, device.Identifier)
directory, err := parseDownloadDirectory(&ipsw, &device)

if err != nil {
log.Printf("Unable to parse download directory, err: %s", err)
Expand Down Expand Up @@ -222,7 +222,13 @@ func downloadWithProgressBar(ipsw *api.Firmware, downloadPath string) error {
return nil
}

func parseDownloadDirectory(fw *api.Firmware, identifier string) (string, error) {
type fwDeviceCombo struct {
Identifier string
*api.BaseDevice
*api.Firmware
}

func parseDownloadDirectory(fw *api.Firmware, device *api.BaseDevice) (string, error) {
directoryBuffer := new(bytes.Buffer)

t, err := template.New("firmware").Parse(downloadDirectoryTemplate)
Expand All @@ -231,10 +237,7 @@ func parseDownloadDirectory(fw *api.Firmware, identifier string) (string, error)
return "", err
}

// add the identifier, for simplicity
fw.Identifier = identifier

err = t.Execute(directoryBuffer, fw)
err = t.Execute(directoryBuffer, &fwDeviceCombo{device.Identifier, device, fw})

if err != nil {
return "", nil
Expand Down

0 comments on commit 03b1dfb

Please sign in to comment.