66 lines
1.7 KiB
Go
66 lines
1.7 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"`
|
|
}
|
|
|
|
func Run() {
|
|
var args args
|
|
p := arg.MustParse(&args)
|
|
|
|
switch {
|
|
case args.Scan != nil:
|
|
oplcli.Scan(args.Scan.Files, oplcli.Config{})
|
|
case args.Rename != nil:
|
|
oplcli.Rename(args.Rename.Files, oplcli.Config{})
|
|
case args.Art != nil:
|
|
oplcli.DownloadGameArt(args.Art.Files, args.Art.OutputDirectory, oplcli.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, oplcli.Config{})
|
|
default:
|
|
p.Fail("Must specify command")
|
|
}
|
|
}
|