intake/cmd/sourceDelete.go

42 lines
800 B
Go
Raw Permalink 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 sourceDeleteCmd = &cobra.Command{
2025-01-23 15:55:11 +00:00
Use: "delete",
Aliases: []string{"rm"},
Short: "Delete a source",
Long: `Delete 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
sourceDelete()
2025-01-21 16:42:59 +00:00
},
}
2025-01-23 15:55:11 +00:00
var sourceDeleteSource string
2025-01-21 16:42:59 +00:00
func init() {
sourceCmd.AddCommand(sourceDeleteCmd)
2025-01-23 15:55:11 +00:00
sourceDeleteCmd.Flags().StringVarP(&sourceDeleteSource, "source", "s", "", "Source to delete")
}
func sourceDelete() {
if sourceDeleteSource == "" {
log.Fatal("error: --source is empty")
}
db := openAndMigrateDb()
if err := core.DeleteSource(db, sourceDeleteSource); err != nil {
2025-01-23 21:22:38 +00:00
log.Fatalf("error: failed to delete source: %v", err)
2025-01-23 15:55:11 +00:00
}
log.Printf("Deleted source %s", sourceDeleteSource)
2025-01-21 16:42:59 +00:00
}