package main import ( "fmt" "github.com/urfave/cli/v2" "log" "os" "path/filepath" "traktorNmlUtils/models/collection" "traktorNmlUtils/models/history" ) // Most of this code is based on the original python library https://github.com/wolkenarchitekt/traktor-nml-utils/ thus is subject to the same license reference it at LICENSE.txt func main() { app := &cli.App{ Flags: []cli.Flag{ &cli.IntFlag{ Name: "verbose", Aliases: []string{"v"}, Usage: "Verbose logging", }, &cli.BoolFlag{ Name: "debug", Usage: "Debug logging", }, }, Commands: []*cli.Command{ { Name: "import", Usage: "NML import from file or directory", Action: func(c *cli.Context) error { nml := c.Args().Get(0) if nml == "" { return fmt.Errorf("no NML file or directory specified") } return importFile(nml) }, }, }, } err := app.Run(os.Args) if err != nil { log.Fatal(err) } } func importFile(nml string) error { err := filepath.Walk(nml, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if !info.IsDir() && filepath.Ext(path) == ".nml" { fmt.Printf("Importing NML: %s\n", path) if history.IsHistoryFile(path) { toHistory, err := history.ReadFileAndConvertToHistory(path) if err != nil { return err } fmt.Printf("Imported %d history entries\n", toHistory.Collection.Entries) } else { toCollection, err := collection.ReadFileAndConvertToCollection(path) if err != nil { return err } fmt.Printf("Imported %d collection entries\n", len(toCollection.Collection.Entry)) } } return nil }) return err }