intake/cmd/sourceAdd.go

42 lines
743 B
Go
Raw Normal View History

2025-01-21 16:42:59 +00:00
package cmd
import (
"log"
2025-01-23 15:55:11 +00:00
"github.com/Jaculabilis/intake/core"
2025-01-21 16:42:59 +00:00
"github.com/spf13/cobra"
)
var sourceAddCmd = &cobra.Command{
Use: "add",
Short: "Create a source",
2025-01-23 15:55:11 +00:00
Long: `Create a source.
2025-01-21 16:42:59 +00:00
`,
Run: func(cmd *cobra.Command, args []string) {
2025-01-23 15:55:11 +00:00
sourceAdd()
2025-01-21 16:42:59 +00:00
},
}
2025-01-23 15:55:11 +00:00
var sourceAddSource string
2025-01-21 16:42:59 +00:00
func init() {
sourceCmd.AddCommand(sourceAddCmd)
2025-01-23 15:55:11 +00:00
sourceAddCmd.Flags().StringVarP(&sourceAddSource, "source", "s", "", "Source name")
sourceAddCmd.MarkFlagRequired("source")
}
func sourceAdd() {
if sourceAddSource == "" {
log.Fatal("error: --source is empty")
}
db := openAndMigrateDb()
if err := core.AddSource(db, sourceAddSource); err != nil {
log.Fatalf("error: %v", err)
}
log.Printf("Added source %s", sourceAddSource)
2025-01-21 16:42:59 +00:00
}