cli args improvements

This commit is contained in:
2026-01-06 20:31:25 +01:00
parent 72f7b44f98
commit 8d308178eb
2 changed files with 8 additions and 16 deletions

View File

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

View File

@@ -61,7 +61,7 @@ func Rename(files []string, config Config) {
} }
} }
func DownloadGameArt(files []string, config Config) { func DownloadGameArt(files []string, output string, config Config) {
for _, file := range files { for _, file := range files {
fmt.Printf("Scanning file: %s\n", file) fmt.Printf("Scanning file: %s\n", file)
@@ -73,6 +73,6 @@ func DownloadGameArt(files []string, config Config) {
fmt.Printf("Found game ID: %s\n", gameID) fmt.Printf("Found game ID: %s\n", gameID)
downloadArtForGame(gameID, "./ignore") downloadArtForGame(gameID, output)
} }
} }