allow multiple files to be processed

This commit is contained in:
2026-01-06 19:17:55 +01:00
parent ff35f6ecd5
commit 72f7b44f98
2 changed files with 63 additions and 49 deletions

View File

@@ -6,15 +6,15 @@ import (
) )
type ScanCmd struct { type ScanCmd struct {
File string `arg:"positional"` Files []string `arg:"positional"`
} }
type RenameCmd struct { type RenameCmd struct {
File string `arg:"positional"` Files []string `arg:"positional"`
} }
type ArtCmd struct { type ArtCmd struct {
File string `arg:"positional"` Files []string `arg:"positional"`
} }
type args struct { type args struct {
@@ -25,14 +25,23 @@ type args struct {
func Run() { func Run() {
var args args var args args
arg.MustParse(&args) p := arg.MustParse(&args)
switch { switch {
case args.Scan != nil: case args.Scan != nil:
oplcli.Scan(args.Scan.File, oplcli.Config{}) if len(args.Scan.Files) == 0 {
p.Fail("Provide at least one file to scan")
}
oplcli.Scan(args.Scan.Files, oplcli.Config{})
case args.Rename != nil: case args.Rename != nil:
oplcli.Rename(args.Rename.File, oplcli.Config{}) if len(args.Rename.Files) == 0 {
p.Fail("Provide at least one file rename")
}
oplcli.Rename(args.Rename.Files, oplcli.Config{})
case args.Art != nil: case args.Art != nil:
oplcli.DownloadGameArt(args.Art.File, oplcli.Config{}) if len(args.Art.Files) == 0 {
p.Fail("Provide at least one file to download art for")
}
oplcli.DownloadGameArt(args.Art.Files, oplcli.Config{})
} }
} }

View File

@@ -8,66 +8,71 @@ import (
type Config struct { type Config struct {
} }
func Scan(file string, config Config) { func Scan(files []string, config Config) {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameList, err := loadGamelist("./ps2-gameslist.txt") gameList, err := loadGamelist("./ps2-gameslist.txt")
if err != nil { if err != nil {
fmt.Printf("Failed to load game list: %v", err) fmt.Printf("Failed to load game list: %v", err)
os.Exit(1) os.Exit(1)
} }
gameName := gameList[gameID] for _, file := range files {
fmt.Printf("Found game name: %s\n", gameName) fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
}
} }
func Rename(file string, config Config) { func Rename(files []string, config Config) {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameList, err := loadGamelist("./ps2-gameslist.txt") gameList, err := loadGamelist("./ps2-gameslist.txt")
if err != nil { if err != nil {
fmt.Printf("Failed to load game list: %v", err) fmt.Printf("Failed to load game list: %v", err)
os.Exit(1) os.Exit(1)
} }
gameName := gameList[gameID] for _, file := range files {
fmt.Printf("Found game name: %s\n", gameName) fmt.Printf("Scanning file: %s\n", file)
newPath, err := renameGameFile(file, gameName) gameID, err := scanGameFileForID(file)
if err != nil { if err != nil {
fmt.Printf("Failed to rename file: %v", err) fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1) os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
newPath, err := renameGameFile(file, gameName)
if err != nil {
fmt.Printf("Failed to rename file: %v", err)
os.Exit(1)
}
fmt.Printf("Renamed %s to %s", file, newPath)
} }
fmt.Printf("Renamed %s to %s", file, newPath)
} }
func DownloadGameArt(file string, config Config) { func DownloadGameArt(files []string, config Config) {
fmt.Printf("Scanning file: %s\n", file) for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
gameID, err := scanGameFileForID(file) gameID, err := scanGameFileForID(file)
if err != nil { if err != nil {
fmt.Printf("Failed to scan game file: %s", err) fmt.Printf("Failed to scan game file: %s", err)
os.Exit(1) os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
downloadArtForGame(gameID, "./ignore")
} }
fmt.Printf("Found game ID: %s\n", gameID)
downloadArtForGame(gameID, "./art")
} }