(name string, f util.Factory)
| 36 | const resourceGroupEnv = "RESOURCE_GROUP_INVENTORY" |
| 37 | |
| 38 | func GetLiveCommand(name string, f util.Factory) *cobra.Command { |
| 39 | liveCmd := &cobra.Command{ |
| 40 | Use: "live", |
| 41 | Short: livedocs.LiveShort, |
| 42 | Long: livedocs.LiveShort + "\n" + livedocs.LiveLong, |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | h, err := cmd.Flags().GetBool("help") |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | if h { |
| 49 | return cmd.Help() |
| 50 | } |
| 51 | return cmd.Usage() |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | ioStreams := genericclioptions.IOStreams{ |
| 56 | In: os.Stdin, |
| 57 | Out: os.Stdout, |
| 58 | ErrOut: os.Stderr, |
| 59 | } |
| 60 | |
| 61 | // The default provider is for ConfigMap inventory, but if the magic env |
| 62 | // var exists, then the provider which handles both ConfigMap and ResourceGroup |
| 63 | // inventory objects is used. If a package has both inventory objects, then |
| 64 | // an error is thrown. |
| 65 | var p provider.Provider = provider.NewProvider(f) |
| 66 | var l manifestreader.ManifestLoader = manifestreader.NewManifestLoader(f) |
| 67 | if _, exists := os.LookupEnv(resourceGroupEnv); exists { |
| 68 | klog.V(2).Infoln("provider supports ResourceGroup and ConfigMap inventory") |
| 69 | p = live.NewDualDelegatingProvider(f) |
| 70 | l = live.NewDualDelegatingManifestReader(f) |
| 71 | } |
| 72 | |
| 73 | // The default init command creates the ConfigMap inventory yaml. If the magic |
| 74 | // env var exists, then we use the init command which updates a Kptfile for |
| 75 | // the ResourceGroup inventory object. |
| 76 | initCmd := initcmd.NewCmdInit(f, ioStreams) |
| 77 | if _, exists := os.LookupEnv(resourceGroupEnv); exists { |
| 78 | klog.V(2).Infoln("init command updates Kptfile for ResourceGroup inventory") |
| 79 | initCmd = NewCmdInit(f, ioStreams) |
| 80 | } |
| 81 | initCmd.Short = livedocs.InitShort |
| 82 | initCmd.Long = livedocs.InitShort + "\n" + livedocs.InitLong |
| 83 | initCmd.Example = livedocs.InitExamples |
| 84 | |
| 85 | applyCmd := GetApplyRunner(p, l, ioStreams).Command() |
| 86 | _ = applyCmd.Flags().MarkHidden("no-prune") |
| 87 | applyCmd.Short = livedocs.ApplyShort |
| 88 | applyCmd.Long = livedocs.ApplyShort + "\n" + livedocs.ApplyLong |
| 89 | applyCmd.Example = livedocs.ApplyExamples |
| 90 | |
| 91 | previewCmd := GetPreviewRunner(p, l, ioStreams).Command() |
| 92 | previewCmd.Short = livedocs.PreviewShort |
| 93 | previewCmd.Long = livedocs.PreviewShort + "\n" + livedocs.PreviewLong |
| 94 | previewCmd.Example = livedocs.PreviewExamples |
| 95 |
no test coverage detected