package cmd import ( "log" "os" "git.agecem.com/agecem/bottin/bottin" "git.agecem.com/agecem/bottin/data" "github.com/spf13/cobra" ) // importCmd represents the import command var importCmd = &cobra.Command{ Use: "import", Short: "Import content into the database", Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { log.Fatal("Not enough arguments, needs at least 1 path") } else { data.OpenDatabase() data.MigrateDatabase() bottin.UpdateFlags() var valid_args []string for _, arg := range args { _, err := os.Stat(arg) if !os.IsNotExist(err) { log.Printf("Adding %s to valid_args", arg) valid_args = append(valid_args, arg) } } // Import from valid args if len(valid_args) == 1 { // Do once bottin.InsertJson(valid_args[0]) } else { // Do multiple times for _, path := range valid_args { bottin.InsertJson(path) } } } }, } func init() { rootCmd.AddCommand(importCmd) }