// Package modulescmd lists provider modules discovered under modules//, // building them on demand and showing channels + values paths. package modulescmd import ( "flag" "fmt" "os" "sort" "text/tabwriter" "streamd/modhost" "streamd/repo" ) // Run prints external modules under modules/. func Run(args []string) error { fs := flag.NewFlagSet("modules", flag.ExitOnError) verbose := fs.Bool("channels", true, "list each module's channels") if err := fs.Parse(args); err != nil { return err } root := repo.Root() listed, err := modhost.ListAll(root) if err != nil { return err } if len(listed) == 0 { return fmt.Errorf("no modules found under %s — add modules// with Go source + module.yaml (see modules/README.md)", modhost.ModulesDir(root)) } tw := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) fmt.Fprintln(tw, "APP\tPACKAGE\tKEY MODE\tREWRITER\tCHANNELS\tVALUES") for _, L := range listed { d := L.Desc rewriter := d.Rewriter if rewriter == "" { rewriter = "none" } pkg := d.Package if pkg == "" { pkg = "(not configured)" } values := d.ValuesPath if values == "" { values = L.Mod.Dir + string(os.PathSeparator) + "module.yaml" } if _, err := os.Stat(values); err != nil { values = "missing: " + values } else if !d.ValuesLoaded { values = values + " (not loaded)" } fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%d\t%s\n", d.Name, pkg, d.KeyMode, rewriter, len(d.Channels), values) } _ = tw.Flush() if !*verbose { return nil } for _, L := range listed { d := L.Desc chans := append([]modhost.Channel{}, d.Channels...) sort.Slice(chans, func(i, j int) bool { return chans[i].ID < chans[j].ID }) fmt.Printf("\n%s channels:", d.Name) if len(chans) == 0 { fmt.Printf(" none — add %s\n", d.ValuesPath) continue } fmt.Println() for _, ch := range chans { catalog := "" if d.HasCatalog { catalog = " (catalog)" } fmt.Printf(" %-10s %s%s\n", ch.ID, ch.Label, catalog) } } return nil }