|
@@ -2,8 +2,13 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
+ "os"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
+ "github.com/hexops/gotextdiff"
|
|
|
+ "github.com/hexops/gotextdiff/myers"
|
|
|
+ "github.com/hexops/gotextdiff/span"
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
@@ -35,27 +40,27 @@ type cliItem struct {
|
|
|
listHelp cliHelp
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewCommand() *cobra.Command {
|
|
|
+func (cli cliItem) NewCommand() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.help.use, fmt.Sprintf("%s <action> [item]...", it.name)),
|
|
|
- Short: coalesce.String(it.help.short, fmt.Sprintf("Manage hub %s", it.name)),
|
|
|
- Long: it.help.long,
|
|
|
- Example: it.help.example,
|
|
|
+ Use: coalesce.String(cli.help.use, fmt.Sprintf("%s <action> [item]...", cli.name)),
|
|
|
+ Short: coalesce.String(cli.help.short, fmt.Sprintf("Manage hub %s", cli.name)),
|
|
|
+ Long: cli.help.long,
|
|
|
+ Example: cli.help.example,
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
- Aliases: []string{it.singular},
|
|
|
+ Aliases: []string{cli.singular},
|
|
|
DisableAutoGenTag: true,
|
|
|
}
|
|
|
|
|
|
- cmd.AddCommand(it.NewInstallCmd())
|
|
|
- cmd.AddCommand(it.NewRemoveCmd())
|
|
|
- cmd.AddCommand(it.NewUpgradeCmd())
|
|
|
- cmd.AddCommand(it.NewInspectCmd())
|
|
|
- cmd.AddCommand(it.NewListCmd())
|
|
|
+ cmd.AddCommand(cli.NewInstallCmd())
|
|
|
+ cmd.AddCommand(cli.NewRemoveCmd())
|
|
|
+ cmd.AddCommand(cli.NewUpgradeCmd())
|
|
|
+ cmd.AddCommand(cli.NewInspectCmd())
|
|
|
+ cmd.AddCommand(cli.NewListCmd())
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) Install(cmd *cobra.Command, args []string) error {
|
|
|
+func (cli cliItem) Install(cmd *cobra.Command, args []string) error {
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
downloadOnly, err := flags.GetBool("download-only")
|
|
@@ -79,9 +84,9 @@ func (it cliItem) Install(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
|
|
|
for _, name := range args {
|
|
|
- item := hub.GetItem(it.name, name)
|
|
|
+ item := hub.GetItem(cli.name, name)
|
|
|
if item == nil {
|
|
|
- msg := suggestNearestMessage(hub, it.name, name)
|
|
|
+ msg := suggestNearestMessage(hub, cli.name, name)
|
|
|
if !ignoreError {
|
|
|
return fmt.Errorf(msg)
|
|
|
}
|
|
@@ -103,24 +108,24 @@ func (it cliItem) Install(cmd *cobra.Command, args []string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewInstallCmd() *cobra.Command {
|
|
|
+func (cli cliItem) NewInstallCmd() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.installHelp.use, "install [item]..."),
|
|
|
- Short: coalesce.String(it.installHelp.short, fmt.Sprintf("Install given %s", it.oneOrMore)),
|
|
|
- Long: coalesce.String(it.installHelp.long, fmt.Sprintf("Fetch and install one or more %s from the hub", it.name)),
|
|
|
- Example: it.installHelp.example,
|
|
|
+ Use: coalesce.String(cli.installHelp.use, "install [item]..."),
|
|
|
+ Short: coalesce.String(cli.installHelp.short, fmt.Sprintf("Install given %s", cli.oneOrMore)),
|
|
|
+ Long: coalesce.String(cli.installHelp.long, fmt.Sprintf("Fetch and install one or more %s from the hub", cli.name)),
|
|
|
+ Example: cli.installHelp.example,
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
DisableAutoGenTag: true,
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
- return compAllItems(it.name, args, toComplete)
|
|
|
+ return compAllItems(cli.name, args, toComplete)
|
|
|
},
|
|
|
- RunE: it.Install,
|
|
|
+ RunE: cli.Install,
|
|
|
}
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
flags.BoolP("download-only", "d", false, "Only download packages, don't enable")
|
|
|
flags.Bool("force", false, "Force install: overwrite tainted and outdated files")
|
|
|
- flags.Bool("ignore", false, fmt.Sprintf("Ignore errors when installing multiple %s", it.name))
|
|
|
+ flags.Bool("ignore", false, fmt.Sprintf("Ignore errors when installing multiple %s", cli.name))
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
@@ -138,7 +143,7 @@ func istalledParentNames(item *cwhub.Item) []string {
|
|
|
return ret
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
+func (cli cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
purge, err := flags.GetBool("purge")
|
|
@@ -167,7 +172,7 @@ func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
getter = hub.GetAllItems
|
|
|
}
|
|
|
|
|
|
- items, err := getter(it.name)
|
|
|
+ items, err := getter(cli.name)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -185,7 +190,7 @@ func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.Infof("Removed %d %s", removed, it.name)
|
|
|
+ log.Infof("Removed %d %s", removed, cli.name)
|
|
|
if removed > 0 {
|
|
|
log.Infof(ReloadMessage())
|
|
|
}
|
|
@@ -194,22 +199,23 @@ func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
- return fmt.Errorf("specify at least one %s to remove or '--all'", it.singular)
|
|
|
+ return fmt.Errorf("specify at least one %s to remove or '--all'", cli.singular)
|
|
|
}
|
|
|
|
|
|
removed := 0
|
|
|
|
|
|
for _, itemName := range args {
|
|
|
- item := hub.GetItem(it.name, itemName)
|
|
|
+ item := hub.GetItem(cli.name, itemName)
|
|
|
if item == nil {
|
|
|
- return fmt.Errorf("can't find '%s' in %s", itemName, it.name)
|
|
|
+ return fmt.Errorf("can't find '%s' in %s", itemName, cli.name)
|
|
|
}
|
|
|
|
|
|
parents := istalledParentNames(item)
|
|
|
|
|
|
if !force && len(parents) > 0 {
|
|
|
log.Warningf("%s belongs to collections: %s", item.Name, parents)
|
|
|
- log.Warningf("Run 'sudo cscli %s remove %s --force' if you want to force remove this %s", item.Type, item.Name, it.singular)
|
|
|
+ log.Warningf("Run 'sudo cscli %s remove %s --force' if you want to force remove this %s", item.Type, item.Name, cli.singular)
|
|
|
+
|
|
|
continue
|
|
|
}
|
|
|
|
|
@@ -224,7 +230,7 @@ func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.Infof("Removed %d %s", removed, it.name)
|
|
|
+ log.Infof("Removed %d %s", removed, cli.name)
|
|
|
if removed > 0 {
|
|
|
log.Infof(ReloadMessage())
|
|
|
}
|
|
@@ -232,29 +238,29 @@ func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewRemoveCmd() *cobra.Command {
|
|
|
+func (cli cliItem) NewRemoveCmd() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.removeHelp.use, "remove [item]..."),
|
|
|
- Short: coalesce.String(it.removeHelp.short, fmt.Sprintf("Remove given %s", it.oneOrMore)),
|
|
|
- Long: coalesce.String(it.removeHelp.long, fmt.Sprintf("Remove one or more %s", it.name)),
|
|
|
- Example: it.removeHelp.example,
|
|
|
+ Use: coalesce.String(cli.removeHelp.use, "remove [item]..."),
|
|
|
+ Short: coalesce.String(cli.removeHelp.short, fmt.Sprintf("Remove given %s", cli.oneOrMore)),
|
|
|
+ Long: coalesce.String(cli.removeHelp.long, fmt.Sprintf("Remove one or more %s", cli.name)),
|
|
|
+ Example: cli.removeHelp.example,
|
|
|
Aliases: []string{"delete"},
|
|
|
DisableAutoGenTag: true,
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
- return compInstalledItems(it.name, args, toComplete)
|
|
|
+ return compInstalledItems(cli.name, args, toComplete)
|
|
|
},
|
|
|
- RunE: it.Remove,
|
|
|
+ RunE: cli.Remove,
|
|
|
}
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
flags.Bool("purge", false, "Delete source file too")
|
|
|
flags.Bool("force", false, "Force remove: remove tainted and outdated files")
|
|
|
- flags.Bool("all", false, fmt.Sprintf("Remove all the %s", it.name))
|
|
|
+ flags.Bool("all", false, fmt.Sprintf("Remove all the %s", cli.name))
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
+func (cli cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
force, err := flags.GetBool("force")
|
|
@@ -273,7 +279,7 @@ func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
|
|
|
if all {
|
|
|
- items, err := hub.GetInstalledItems(it.name)
|
|
|
+ items, err := hub.GetInstalledItems(cli.name)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
@@ -290,7 +296,7 @@ func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.Infof("Updated %d %s", updated, it.name)
|
|
|
+ log.Infof("Updated %d %s", updated, cli.name)
|
|
|
|
|
|
if updated > 0 {
|
|
|
log.Infof(ReloadMessage())
|
|
@@ -300,15 +306,15 @@ func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
}
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
- return fmt.Errorf("specify at least one %s to upgrade or '--all'", it.singular)
|
|
|
+ return fmt.Errorf("specify at least one %s to upgrade or '--all'", cli.singular)
|
|
|
}
|
|
|
|
|
|
updated := 0
|
|
|
|
|
|
for _, itemName := range args {
|
|
|
- item := hub.GetItem(it.name, itemName)
|
|
|
+ item := hub.GetItem(cli.name, itemName)
|
|
|
if item == nil {
|
|
|
- return fmt.Errorf("can't find '%s' in %s", itemName, it.name)
|
|
|
+ return fmt.Errorf("can't find '%s' in %s", itemName, cli.name)
|
|
|
}
|
|
|
|
|
|
didUpdate, err := item.Upgrade(force)
|
|
@@ -328,27 +334,27 @@ func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewUpgradeCmd() *cobra.Command {
|
|
|
+func (cli cliItem) NewUpgradeCmd() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.upgradeHelp.use, "upgrade [item]..."),
|
|
|
- Short: coalesce.String(it.upgradeHelp.short, fmt.Sprintf("Upgrade given %s", it.oneOrMore)),
|
|
|
- Long: coalesce.String(it.upgradeHelp.long, fmt.Sprintf("Fetch and upgrade one or more %s from the hub", it.name)),
|
|
|
- Example: it.upgradeHelp.example,
|
|
|
+ Use: coalesce.String(cli.upgradeHelp.use, "upgrade [item]..."),
|
|
|
+ Short: coalesce.String(cli.upgradeHelp.short, fmt.Sprintf("Upgrade given %s", cli.oneOrMore)),
|
|
|
+ Long: coalesce.String(cli.upgradeHelp.long, fmt.Sprintf("Fetch and upgrade one or more %s from the hub", cli.name)),
|
|
|
+ Example: cli.upgradeHelp.example,
|
|
|
DisableAutoGenTag: true,
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
- return compInstalledItems(it.name, args, toComplete)
|
|
|
+ return compInstalledItems(cli.name, args, toComplete)
|
|
|
},
|
|
|
- RunE: it.Upgrade,
|
|
|
+ RunE: cli.Upgrade,
|
|
|
}
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
- flags.BoolP("all", "a", false, fmt.Sprintf("Upgrade all the %s", it.name))
|
|
|
+ flags.BoolP("all", "a", false, fmt.Sprintf("Upgrade all the %s", cli.name))
|
|
|
flags.Bool("force", false, "Force upgrade: overwrite tainted and outdated files")
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) Inspect(cmd *cobra.Command, args []string) error {
|
|
|
+func (cli cliItem) Inspect(cmd *cobra.Command, args []string) error {
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
url, err := flags.GetString("url")
|
|
@@ -360,27 +366,50 @@ func (it cliItem) Inspect(cmd *cobra.Command, args []string) error {
|
|
|
csConfig.Cscli.PrometheusUrl = url
|
|
|
}
|
|
|
|
|
|
+ diff, err := flags.GetBool("diff")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ rev, err := flags.GetBool("rev")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
noMetrics, err := flags.GetBool("no-metrics")
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- hub, err := require.Hub(csConfig, nil)
|
|
|
+ remote := (*cwhub.RemoteHubCfg)(nil)
|
|
|
+
|
|
|
+ if diff {
|
|
|
+ remote = require.RemoteHub(csConfig)
|
|
|
+ }
|
|
|
+
|
|
|
+ hub, err := require.Hub(csConfig, remote)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
for _, name := range args {
|
|
|
- item := hub.GetItem(it.name, name)
|
|
|
+ item := hub.GetItem(cli.name, name)
|
|
|
if item == nil {
|
|
|
- return fmt.Errorf("can't find '%s' in %s", name, it.name)
|
|
|
+ return fmt.Errorf("can't find '%s' in %s", name, cli.name)
|
|
|
+ }
|
|
|
+
|
|
|
+ if diff {
|
|
|
+ fmt.Println(cli.whyTainted(hub, item, rev))
|
|
|
+
|
|
|
+ continue
|
|
|
}
|
|
|
+
|
|
|
if err = InspectItem(item, !noMetrics); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- if it.inspectDetail != nil {
|
|
|
- if err = it.inspectDetail(item); err != nil {
|
|
|
+ if cli.inspectDetail != nil {
|
|
|
+ if err = cli.inspectDetail(item); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
@@ -389,28 +418,49 @@ func (it cliItem) Inspect(cmd *cobra.Command, args []string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewInspectCmd() *cobra.Command {
|
|
|
+func (cli cliItem) NewInspectCmd() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.inspectHelp.use, "inspect [item]..."),
|
|
|
- Short: coalesce.String(it.inspectHelp.short, fmt.Sprintf("Inspect given %s", it.oneOrMore)),
|
|
|
- Long: coalesce.String(it.inspectHelp.long, fmt.Sprintf("Inspect the state of one or more %s", it.name)),
|
|
|
- Example: it.inspectHelp.example,
|
|
|
+ Use: coalesce.String(cli.inspectHelp.use, "inspect [item]..."),
|
|
|
+ Short: coalesce.String(cli.inspectHelp.short, fmt.Sprintf("Inspect given %s", cli.oneOrMore)),
|
|
|
+ Long: coalesce.String(cli.inspectHelp.long, fmt.Sprintf("Inspect the state of one or more %s", cli.name)),
|
|
|
+ Example: cli.inspectHelp.example,
|
|
|
Args: cobra.MinimumNArgs(1),
|
|
|
DisableAutoGenTag: true,
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
- return compInstalledItems(it.name, args, toComplete)
|
|
|
+ return compInstalledItems(cli.name, args, toComplete)
|
|
|
+ },
|
|
|
+ PreRunE: func(cmd *cobra.Command, _ []string) error {
|
|
|
+ flags := cmd.Flags()
|
|
|
+
|
|
|
+ diff, err := flags.GetBool("diff")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ rev, err := flags.GetBool("rev")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if rev && !diff {
|
|
|
+ return fmt.Errorf("--rev can only be used with --diff")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
},
|
|
|
- RunE: it.Inspect,
|
|
|
+ RunE: cli.Inspect,
|
|
|
}
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
flags.StringP("url", "u", "", "Prometheus url")
|
|
|
+ flags.Bool("diff", false, "Show diff with latest version (for tainted items)")
|
|
|
+ flags.Bool("rev", false, "Reverse diff output")
|
|
|
flags.Bool("no-metrics", false, "Don't show metrics (when cscli.output=human)")
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) List(cmd *cobra.Command, args []string) error {
|
|
|
+func (cli cliItem) List(cmd *cobra.Command, args []string) error {
|
|
|
flags := cmd.Flags()
|
|
|
|
|
|
all, err := flags.GetBool("all")
|
|
@@ -425,26 +475,26 @@ func (it cliItem) List(cmd *cobra.Command, args []string) error {
|
|
|
|
|
|
items := make(map[string][]*cwhub.Item)
|
|
|
|
|
|
- items[it.name], err = selectItems(hub, it.name, args, !all)
|
|
|
+ items[cli.name], err = selectItems(hub, cli.name, args, !all)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- if err = listItems(color.Output, []string{it.name}, items, false); err != nil {
|
|
|
+ if err = listItems(color.Output, []string{cli.name}, items, false); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (it cliItem) NewListCmd() *cobra.Command {
|
|
|
+func (cli cliItem) NewListCmd() *cobra.Command {
|
|
|
cmd := &cobra.Command{
|
|
|
- Use: coalesce.String(it.listHelp.use, "list [item... | -a]"),
|
|
|
- Short: coalesce.String(it.listHelp.short, fmt.Sprintf("List %s", it.oneOrMore)),
|
|
|
- Long: coalesce.String(it.listHelp.long, fmt.Sprintf("List of installed/available/specified %s", it.name)),
|
|
|
- Example: it.listHelp.example,
|
|
|
+ Use: coalesce.String(cli.listHelp.use, "list [item... | -a]"),
|
|
|
+ Short: coalesce.String(cli.listHelp.short, fmt.Sprintf("List %s", cli.oneOrMore)),
|
|
|
+ Long: coalesce.String(cli.listHelp.long, fmt.Sprintf("List of installed/available/specified %s", cli.name)),
|
|
|
+ Example: cli.listHelp.example,
|
|
|
DisableAutoGenTag: true,
|
|
|
- RunE: it.List,
|
|
|
+ RunE: cli.List,
|
|
|
}
|
|
|
|
|
|
flags := cmd.Flags()
|
|
@@ -452,3 +502,75 @@ func (it cliItem) NewListCmd() *cobra.Command {
|
|
|
|
|
|
return cmd
|
|
|
}
|
|
|
+
|
|
|
+// return the diff between the installed version and the latest version
|
|
|
+func (cli cliItem) itemDiff(item *cwhub.Item, reverse bool) (string, error) {
|
|
|
+ if !item.State.Installed {
|
|
|
+ return "", fmt.Errorf("'%s' is not installed", item.FQName())
|
|
|
+ }
|
|
|
+
|
|
|
+ latestContent, remoteURL, err := item.FetchLatest()
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+
|
|
|
+ localContent, err := os.ReadFile(item.State.LocalPath)
|
|
|
+ if err != nil {
|
|
|
+ return "", fmt.Errorf("while reading %s: %w", item.State.LocalPath, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ file1 := item.State.LocalPath
|
|
|
+ file2 := remoteURL
|
|
|
+ content1 := string(localContent)
|
|
|
+ content2 := string(latestContent)
|
|
|
+ if reverse {
|
|
|
+ file1, file2 = file2, file1
|
|
|
+ content1, content2 = content2, content1
|
|
|
+ }
|
|
|
+
|
|
|
+ edits := myers.ComputeEdits(span.URIFromPath(file1), content1, content2)
|
|
|
+ diff := gotextdiff.ToUnified(file1, file2, content1, edits)
|
|
|
+
|
|
|
+ return fmt.Sprintf("%s", diff), nil
|
|
|
+}
|
|
|
+
|
|
|
+func (cli cliItem) whyTainted(hub *cwhub.Hub, item *cwhub.Item, reverse bool) string {
|
|
|
+ if !item.State.Installed {
|
|
|
+ return fmt.Sprintf("# %s is not installed", item.FQName())
|
|
|
+ }
|
|
|
+
|
|
|
+ if !item.State.Tainted {
|
|
|
+ return fmt.Sprintf("# %s is not tainted", item.FQName())
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(item.State.TaintedBy) == 0 {
|
|
|
+ return fmt.Sprintf("# %s is tainted but we don't know why. please report this as a bug", item.FQName())
|
|
|
+ }
|
|
|
+
|
|
|
+ ret := []string{
|
|
|
+ fmt.Sprintf("# Let's see why %s is tainted.", item.FQName()),
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, fqsub := range item.State.TaintedBy {
|
|
|
+ ret = append(ret, fmt.Sprintf("\n-> %s\n", fqsub))
|
|
|
+
|
|
|
+ sub, err := hub.GetItemFQ(fqsub)
|
|
|
+ if err != nil {
|
|
|
+ ret = append(ret, err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ diff, err := cli.itemDiff(sub, reverse)
|
|
|
+ if err != nil {
|
|
|
+ ret = append(ret, err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ if diff != "" {
|
|
|
+ ret = append(ret, diff)
|
|
|
+ } else if len(sub.State.TaintedBy) > 0 {
|
|
|
+ taintList := strings.Join(sub.State.TaintedBy, ", ")
|
|
|
+ ret = append(ret, fmt.Sprintf("# %s is tainted by %s", sub.FQName(), taintList))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return strings.Join(ret, "\n")
|
|
|
+}
|