list

package
v0.0.0-...-f042570 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2018 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &command.Command{
	Name: cmdName,

	Cobra: &cobra.Command{
		Use:          cmdName,
		Aliases:      []string{"ls"},
		Short:        "list counts of each VPC type",
		SilenceUsage: true,
		Args:         cobra.NoArgs,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			return nil
		},

		Long: `The list operation of vpc(8) is used to display all VPC objects in the system
and their respective VPC IDs.`,
		Example: `% vpc list
 TYPE     ID                                    UNIT NAME
 ethlink  5c4acd32-1b8d-11e8-b408-0cc47a6c7d1e  ethlink0
 vmnic    07f95a11-6788-2ae7-c306-ba95cff1db38  vmnic0
 vmnic    a774ba3a-1f77-11e8-8006-0cc47a6c7d1e  vmnic1
 vpcp     0ebf50e1-1f79-11e8-8002-0cc47a6c7d1e  vpcp1
 vpcp     ea58b648-203b-a707-cd02-7a552c8d5295  vpcp2
 vpcp     fd436f9c-1f77-11e8-8002-0cc47a6c7d1e  vpcp0
 vpcsw    da64c3f3-095d-91e5-df01-5aabcfc52468  vpcsw0

   TOTAL                    7`,

		RunE: func(cmd *cobra.Command, args []string) error {
			cons := conswriter.GetTerminal()

			if viper.GetBool(keyObjCounts) {
				return listTypeCount(cons)
			}

			return listTypeIDs(cons)
		},
	},

	Setup: func(self *command.Command) error {
		{
			const (
				key          = keyObjCounts
				longName     = "obj-counts"
				shortName    = "c"
				defaultValue = false
				description  = "list the number of objects per type"
			)

			flags := self.Cobra.Flags()
			flags.BoolP(longName, shortName, defaultValue, description)

			viper.BindPFlag(key, flags.Lookup(longName))
			viper.SetDefault(key, defaultValue)
		}

		{
			const (
				key          = keySortBy
				longName     = "sort-by"
				shortName    = "s"
				defaultValue = "id"
			)
			sortOptions := []string{"id", "name"}
			sortOptionsStr := strings.Join(sortOptions, ", ")
			description := fmt.Sprintf("Change the sort order within a given type: %s", sortOptionsStr)

			flags := self.Cobra.Flags()
			flags.StringP(longName, shortName, defaultValue, description)

			viper.BindPFlag(key, flags.Lookup(longName))
			viper.SetDefault(key, defaultValue)
		}

		{
			const (
				key          = keyType
				longName     = "obj-type"
				shortName    = "t"
				defaultValue = "all"
			)
			objTypes := vpc.ObjTypes()
			sort.SliceStable(objTypes, func(i, j int) bool { return objTypes[i].String() < objTypes[j].String() })

			objTypesStrs := make([]string, len(objTypes))
			for i := range objTypes {
				objTypesStrs[i] = objTypes[i].String()
			}
			objTypesStr := strings.Join(objTypesStrs, ", ")
			description := fmt.Sprintf("List objects of a given type. Valid types: %s", objTypesStr)

			flags := self.Cobra.Flags()
			flags.StringP(longName, shortName, defaultValue, description)

			viper.BindPFlag(key, flags.Lookup(longName))
			viper.SetDefault(key, defaultValue)
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL