2025-01-23 15:55:11 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var sourceListCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Aliases: []string{"ls"},
|
|
|
|
Short: "List sources",
|
|
|
|
Long: `Print the list of sources.
|
|
|
|
`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
sourceList()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2025-01-23 16:22:50 +00:00
|
|
|
var sourceListShowActions bool
|
|
|
|
|
2025-01-23 15:55:11 +00:00
|
|
|
func init() {
|
|
|
|
sourceCmd.AddCommand(sourceListCmd)
|
2025-01-23 16:22:50 +00:00
|
|
|
|
|
|
|
sourceListCmd.Flags().BoolVarP(&sourceListShowActions, "actions", "a", false, "Include source actions")
|
2025-01-23 15:55:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func sourceList() {
|
|
|
|
db := openAndMigrateDb()
|
|
|
|
|
|
|
|
names, err := core.GetSources(db)
|
|
|
|
if err != nil {
|
2025-01-23 21:22:38 +00:00
|
|
|
log.Fatalf("error: failed to get sources: %v", err)
|
2025-01-23 15:55:11 +00:00
|
|
|
}
|
|
|
|
slices.Sort(names)
|
|
|
|
|
2025-01-23 16:22:50 +00:00
|
|
|
if sourceListShowActions {
|
|
|
|
sourceActions := make(map[string][]string)
|
|
|
|
for _, name := range names {
|
|
|
|
actions, err := core.GetActionsForSource(db, name)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error: could not get actions for source %s: %v", name, err)
|
|
|
|
}
|
|
|
|
slices.SortFunc(actions, actionSort)
|
|
|
|
sourceActions[name] = actions
|
|
|
|
}
|
|
|
|
for _, name := range names {
|
|
|
|
fmt.Printf("%s %v\n", name, sourceActions[name])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for _, name := range names {
|
|
|
|
fmt.Println(name)
|
|
|
|
}
|
2025-01-23 15:55:11 +00:00
|
|
|
}
|
|
|
|
}
|