-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a command to accumulate listed gog updates in update file
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmd | ||
|
||
import ( | ||
"gogcli/gameupdates" | ||
|
||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func generateUpdateAccumulateCmd() *cobra.Command { | ||
var prev *gameupdates.Updates | ||
var concurrency int | ||
var pause int | ||
var updateFile string | ||
var terminalOutput bool | ||
|
||
updateAccumulateCmd := &cobra.Command{ | ||
Use: "accumulate", | ||
Short: "Add to the content of an existing update file based on what is new or got updated in GOG.com", | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
bs, err := ioutil.ReadFile(updateFile) | ||
if err != nil { | ||
fmt.Println("Could not load the update file: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
prev = &gameupdates.Updates{} | ||
err = json.Unmarshal(bs, prev) | ||
if err != nil { | ||
fmt.Println("Update file doesn't appear to contain valid json: ", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
u, errs := sdkPtr.GetUpdates(concurrency, pause) | ||
processErrors(errs) | ||
u.Merge(prev) | ||
processSerializableOutput(u, []error{}, terminalOutput, updateFile) | ||
}, | ||
} | ||
|
||
updateAccumulateCmd.Flags().IntVarP(&concurrency, "concurrency", "r", 4, "Maximum number of concurrent requests that will be made on the GOG api") | ||
updateAccumulateCmd.Flags().IntVarP(&pause, "pause", "s", 200, "Number of milliseconds to wait between batches of api calls") | ||
updateAccumulateCmd.Flags().StringVarP(&updateFile, "update-file", "f", "updates.json", "File to add updates to") | ||
updateAccumulateCmd.Flags().BoolVarP(&terminalOutput, "terminal", "t", false, "If set to true, the updates will be output on the terminal instead of the file") | ||
|
||
return updateAccumulateCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gameupdates | ||
|
||
func min(x int, y int) int { | ||
if x < y { | ||
return x | ||
} | ||
return y | ||
} | ||
|
||
func contains(list []int64, elem int64) bool { | ||
for _, val := range list { | ||
if val == elem { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |