cmd

package
v0.1.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Namespace string
	OName     string // Flag for overriding application name.
	Config    string // Viper config override
	Verbose   bool   = false
	// Output flag, makes mg output generated kubernetes resources in json or yaml.
	Output        bool = false
	Version       string
	Dryrun        bool = false // If true do not create
	Branch        string
	BaseEnvs      bool = false
	Defaults      bool = false // Should we hydrate default values in declarative state.
	Format        string
	Template      string           // Command line flag for setting template name
	Suffix        string           // Command line flag for setting mg create ref output file suffix
	Enforce       bool     = false // Boolean flag for articulating enforcement mode instead of inform
	ImageNS       string           // Image Namespace, used in overriding namespace in container image references
	Registry      string           // Flag for holding a custom container registry
	Tag           string           // Flag to specify tag to work on or target
	Context       string           // Flag for setting application context root.
	CreateGlobals bool     = false // Flag for overriding default behaviour of skipping creation of global secrets.
	CVars         []string         // Slice of strings to hold overridden values.
)

@todo: This should be moved to it's own package to avoid cyclic dependencies since both cmd and modules package use them.

View Source
var InspectCmd = &cobra.Command{
	Use:   "inspect <metaGraf>",
	Short: "inspect a metaGraf specification",
	Long:  `inspect a metaGraf specification and list objects that will be created or patched.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			fmt.Println("Active project is:", viper.Get("namespace"))
			fmt.Println("Missing path to metaGraf specification")
			return
		}

		if len(Namespace) == 0 {
			Namespace = viper.GetString("namespace")
			if len(Namespace) == 0 {
				fmt.Println("Namespace must be supplied")
				os.Exit(1)
			}
		}

		mg := metagraf.Parse(args[0])
		modules.Variables = GetCmdProperties(mg.GetProperties())
		log.V(2).Info("Current MGProperties: ", modules.Variables)

		name := modules.Name(&mg)
		for k, v := range modules.Variables {
			fmt.Println(name, "Variable:", k, v)
		}

		modules.InspectSecrets(&mg)
		modules.InspectConfigMaps(&mg)
	},
}
View Source
var InspectPropertiesCmd = &cobra.Command{
	Use:   "properties <metaGraf>",
	Short: "inspect a metaGraf specification against a properties file",
	Long:  `inspect a metaGraf specification against a properties file.`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			log.Infof("Active project is: %v", viper.Get("namespace"))
			log.Errorf("Missing path to metaGraf specification")
			os.Exit(1)
		}

		if len(args) < 2 {
			log.Errorf("Missing path to properties file")
			os.Exit(1)
		}

		mg := metagraf.Parse(args[0])
		params.PropertiesFile = args[1]
		modules.Variables = GetCmdProperties(mg.GetProperties())

		if !ValidateProperties(modules.Variables) {
			os.Exit(1)
		} else {
			fmt.Printf("The %v configuration is valid for this metaGraf specification.\n", params.PropertiesFile)
		}
	},
}
View Source
var MGBanner string = "mg " + MGVersion
View Source
var MGVersion string
View Source
var ProjectCmd = &cobra.Command{
	Use:   "project <name>",
	Short: "set active project / namespace",
	Long:  `sets the `,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) < 1 {
			fmt.Println("Active project is:", viper.Get("namespace"))
			return
		}
		name := args[0]
		viper.Set("namespace", name)
		err := viper.WriteConfig()
		if err != nil {
			fmt.Println("ERROR:", err)
			return
		}
		fmt.Printf("Active namespace is now %v\n", name)
	},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "mg",
	Short: "mg operates on collections of metaGraf's objects.",
	Long: MGBanner + `is a utility that understands the metaGraf
datastructure and help you generate kubernetes primitives`,
}

Functions

func Execute

func Execute() error

func FlagPassingHack

func FlagPassingHack()

func GetCmdProperties added in v0.1.0

func GetCmdProperties(mgp metagraf.MGProperties) metagraf.MGProperties

Process cmd parameters based on metagraf defined properties.

func MergeAndValidateProperties added in v0.1.0

func MergeAndValidateProperties(base metagraf.MGProperties, merge metagraf.MGProperties, novalidate bool) metagraf.MGProperties

func MgPropertyLineSplit added in v0.1.0

func MgPropertyLineSplit(r rune) bool

Used for splitting --cvfile .properties files with strings.FieldsFunc()

func PropertiesFromCmd added in v0.1.0

func PropertiesFromCmd(mgp metagraf.MGProperties) metagraf.MGProperties

Modifies a MGProperties map with values from --cvars argument. Only supports local environment variables for now.

func PropertiesFromEnv added in v0.1.0

func PropertiesFromEnv(mgp metagraf.MGProperties) metagraf.MGProperties

func ReadPropertiesFile added in v0.1.0

func ReadPropertiesFile(propfile string) metagraf.MGProperties

Reads a properties file and returns a metagraf.MGProperties structure

func ValidateProperties added in v0.1.0

func ValidateProperties(mgprops metagraf.MGProperties) bool

Check if all required MGProperty structs in MGProperties has a value. Returns true if they are valid, false if they are invalid.

Types

type CmdCVars

type CmdCVars []string // Map

func (CmdCVars) Parse

func (v CmdCVars) Parse() CmdVars

Returns a map (CmdVars) parsed from --cvars flag todo: fix parsing of , seperated values for a key

type CmdMessage

type CmdMessage string
var StrActiveProject CmdMessage = "Active project is:"
var StrMalformedVar CmdMessage = "Malformed key=value pair supplied through --cvars :"
var StrMissingCollection CmdMessage = "Missing path to collection of metaGraf specifications."
var StrMissingMetaGraf CmdMessage = "Missing path to metaGraf specification."
var StrMissingNamespace CmdMessage = "Namespace must be supplied or configured."

type CmdVars

type CmdVars map[string]string

type EnvVars

type EnvVars map[string]string // Map for holding addressable key, value pairs from os.Environ().

Type for mg custom variables

Jump to

Keyboard shortcuts

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