Added flags for the output path and dry run
This commit is contained in:
parent
ef8f0436dd
commit
771d88aff5
|
@ -7,26 +7,28 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fmartingr/games-screenshot-mananger/pkg/games"
|
"github.com/fmartingr/games-screenshot-mananger/pkg/games"
|
||||||
"github.com/fmartingr/games-screenshot-mananger/pkg/helpers"
|
"github.com/fmartingr/games-screenshot-mananger/pkg/helpers"
|
||||||
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/steam"
|
"github.com/fmartingr/games-screenshot-mananger/pkg/providers/steam"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AllowedProviders = [...]string{"steam"}
|
var allowedProviders = [...]string{"steam"}
|
||||||
|
|
||||||
const OutputPath string = "./Output/"
|
const defaultOutputPath string = "./Output"
|
||||||
|
const defaultProvider string = "steam"
|
||||||
func main() {
|
const defaultDryRun bool = false
|
||||||
Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Start() {
|
func Start() {
|
||||||
var provider = flag.String("provider", "steam", "steam")
|
var provider = flag.String("provider", defaultProvider, "steam")
|
||||||
|
var outputPath = flag.String("output-path", defaultOutputPath, "The destination path of the screenshots")
|
||||||
|
var dryRun = flag.Bool("dry-run", defaultDryRun, "Use to disable write actions on filesystem")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if helpers.SliceContainsString(AllowedProviders[:], *provider, nil) {
|
if helpers.SliceContainsString(allowedProviders[:], *provider, nil) {
|
||||||
games := getGamesFromProvider(*provider)
|
games := getGamesFromProvider(*provider)
|
||||||
processGames(games)
|
processGames(games, *outputPath, *dryRun)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Provider %s not found!", *provider)
|
log.Printf("Provider %s not found!", *provider)
|
||||||
}
|
}
|
||||||
|
@ -40,11 +42,9 @@ func getGamesFromProvider(provider string) []games.Game {
|
||||||
return games
|
return games
|
||||||
}
|
}
|
||||||
|
|
||||||
func processGames(games []games.Game) {
|
func processGames(games []games.Game, outputPath string, dryRun bool) {
|
||||||
dryRun := false
|
|
||||||
|
|
||||||
for _, game := range games {
|
for _, game := range games {
|
||||||
destinationPath := path.Join(helpers.ExpandUser(OutputPath), game.Platform)
|
destinationPath := path.Join(helpers.ExpandUser(outputPath), game.Platform)
|
||||||
if len(game.Name) > 0 {
|
if len(game.Name) > 0 {
|
||||||
destinationPath = path.Join(destinationPath, game.Name)
|
destinationPath = path.Join(destinationPath, game.Name)
|
||||||
} else {
|
} else {
|
||||||
|
@ -84,7 +84,9 @@ func processGames(games []games.Game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if !dryRun {
|
if dryRun {
|
||||||
|
log.Println(path.Base(screenshot.Path), " -> ", strings.Replace(destinationPath, helpers.ExpandUser(outputPath), "", 1))
|
||||||
|
} else {
|
||||||
helpers.CopyFile(screenshot.Path, destinationPath)
|
helpers.CopyFile(screenshot.Path, destinationPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue