Files
opl-cli/cmd/oplcli.go

71 lines
1.8 KiB
Go

package cmd
import (
oplcli "git.kapelle.org/niklas/opl-cli/internal"
"github.com/alexflint/go-arg"
)
type ScanCmd struct {
Files []string `arg:"positional,required"`
}
type RenameCmd struct {
Files []string `arg:"positional,required"`
}
type ArtCmd struct {
Files []string `arg:"positional,required"`
OutputDirectory string `arg:"--output,-o" help:"where to download art files" default:"."`
}
type CfgCmd struct {
Files []string `arg:"positional,required"`
OutputDirectory string `arg:"--output,-o" help:"where to download cfg files" default:"."`
Override bool `arg:"-f,--force" help:"Override existing cfg files"`
Append bool `arg:"-a,--append" help:"Append to existing cfg files"`
}
type args struct {
Scan *ScanCmd `arg:"subcommand:scan"`
Rename *RenameCmd `arg:"subcommand:rename"`
Art *ArtCmd `arg:"subcommand:art"`
Cfg *CfgCmd `arg:"subcommand:cfg"`
GameListLocation string `args:"--gamelist" default:"./ps2-gameslist.txt" help:"Location of game list"`
}
func Run() {
var args args
p := arg.MustParse(&args)
config := oplcli.Config{
GameListLocation: args.GameListLocation,
}
switch {
case args.Scan != nil:
oplcli.Scan(args.Scan.Files, config)
case args.Rename != nil:
oplcli.Rename(args.Rename.Files, config)
case args.Art != nil:
oplcli.DownloadGameArt(args.Art.Files, args.Art.OutputDirectory, config)
case args.Cfg != nil:
if args.Cfg.Override && args.Cfg.Append {
p.FailSubcommand("Can only append or override cfg files", "cfg")
}
var mode oplcli.FileMode = oplcli.ModeOnlyCreate
if args.Cfg.Append {
mode = oplcli.ModeAppend
}
if args.Cfg.Override {
mode = oplcli.ModeOverride
}
oplcli.DownloadCfg(args.Cfg.Files, args.Cfg.OutputDirectory, mode, config)
default:
p.Fail("Must specify command")
}
}