(ctx context.Context, args []string, interactive bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool)
| 46 | } |
| 47 | |
| 48 | func (cli *cliItem) install(ctx context.Context, args []string, interactive bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool) error { |
| 49 | cfg := cli.cfg() |
| 50 | |
| 51 | hub, err := require.Hub(cfg, log.StandardLogger()) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | plan := hubops.NewActionPlan(hub) |
| 57 | |
| 58 | contentProvider, err := require.HubDownloader(ctx, cfg) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | for _, name := range args { |
| 64 | item := hub.GetItem(cli.name, name) |
| 65 | if item == nil { |
| 66 | msg := suggestNearestMessage(hub, cli.name, name) |
| 67 | if !ignoreError { |
| 68 | return errors.New(msg) |
| 69 | } |
| 70 | |
| 71 | log.Error(msg) |
| 72 | |
| 73 | continue |
| 74 | } |
| 75 | |
| 76 | if err = plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, force)); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | |
| 80 | if !downloadOnly { |
| 81 | if err = plan.AddCommand(hubops.NewEnableCommand(item, force)); err != nil { |
| 82 | return err |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | showPlan := (log.StandardLogger().Level >= log.InfoLevel) |
| 88 | verbosePlan := (cfg.Cscli.Output == "raw") |
| 89 | |
| 90 | err = plan.Execute(ctx, interactive, dryRun, showPlan, verbosePlan) |
| 91 | switch { |
| 92 | case errors.Is(err, hubops.ErrUserCanceled) && err != nil: |
| 93 | // not a real error, and we'll want to print the reload message anyway |
| 94 | fmt.Fprintln(os.Stdout, err.Error()) |
| 95 | case ignoreError: |
| 96 | log.Error(err) |
| 97 | case err != nil: |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | if msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded { |
| 102 | fmt.Fprintln(os.Stdout, "\n"+msg) |
| 103 | } |
| 104 | |
| 105 | return nil |
no test coverage detected