get.porter.sh/porter@v1.3.0/cmd/porter/outputs.go (about)

     1  package main
     2  
     3  import (
     4  	"get.porter.sh/porter/pkg/porter"
     5  	"github.com/spf13/cobra"
     6  )
     7  
     8  func buildInstallationOutputsCommands(p *porter.Porter) *cobra.Command {
     9  	cmd := &cobra.Command{
    10  		Use:     "output",
    11  		Aliases: []string{"outputs"},
    12  		Short:   "Output commands",
    13  		Annotations: map[string]string{
    14  			"group": "resource",
    15  		},
    16  	}
    17  
    18  	cmd.AddCommand(buildBundleOutputShowCommand(p))
    19  	cmd.AddCommand(buildBundleOutputListCommand(p))
    20  
    21  	return cmd
    22  }
    23  
    24  func buildBundleOutputListCommand(p *porter.Porter) *cobra.Command {
    25  	opts := porter.OutputListOptions{}
    26  
    27  	cmd := cobra.Command{
    28  		Use:   "list [--installation|i INSTALLATION]",
    29  		Short: "List installation outputs",
    30  		Long:  "Displays a listing of installation outputs.",
    31  		Example: `  porter installation outputs list
    32      porter installation outputs list --installation another-bundle
    33  `,
    34  		PreRunE: func(cmd *cobra.Command, args []string) error {
    35  			return opts.Validate(args, p.Context)
    36  		},
    37  		RunE: func(cmd *cobra.Command, args []string) error {
    38  			return p.PrintBundleOutputs(cmd.Context(), opts)
    39  		},
    40  	}
    41  
    42  	f := cmd.Flags()
    43  	f.StringVarP(&opts.RawFormat, "output", "o", "plaintext",
    44  		"Specify an output format.  Allowed values: plaintext, json, yaml")
    45  	f.StringVarP(&opts.Namespace, "namespace", "n", "",
    46  		"Namespace in which the installation is defined. Defaults to the global namespace.")
    47  	f.StringVarP(&opts.Name, "installation", "i", "",
    48  		"Specify the installation to which the output belongs.")
    49  
    50  	return &cmd
    51  }
    52  
    53  func buildBundleOutputShowCommand(p *porter.Porter) *cobra.Command {
    54  	opts := porter.OutputShowOptions{}
    55  
    56  	cmd := cobra.Command{
    57  		Use:   "show NAME [--installation|-i INSTALLATION]",
    58  		Short: "Show the output of an installation",
    59  		Long:  "Show the output of an installation",
    60  		Example: `  porter installation output show kubeconfig
    61      porter installation output show subscription-id --installation azure-mysql`,
    62  		PreRunE: func(cmd *cobra.Command, args []string) error {
    63  			return opts.Validate(args, p.Context)
    64  		},
    65  		RunE: func(cmd *cobra.Command, args []string) error {
    66  			return p.ShowBundleOutput(cmd.Context(), &opts)
    67  		},
    68  	}
    69  
    70  	f := cmd.Flags()
    71  	f.StringVarP(&opts.Namespace, "namespace", "n", "",
    72  		"Namespace in which the installation is defined. Defaults to the global namespace.")
    73  	f.StringVarP(&opts.Name, "installation", "i", "",
    74  		"Specify the installation to which the output belongs.")
    75  
    76  	return &cmd
    77  }