cmd

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source

Variables

View Source
var (
	All           bool = false // Flag for indicating all resources, example delete all resources associated with a application.
	Namespace     string
	OName         string // Flag for overriding application name.
	Config        string // Viper config override
	Verbose       bool   = false
	Output        bool   = false
	Version       string
	Dryrun        bool = false // If true do not create
	Branch        string
	Replicas      int  = 1 // Flag for adjusting number of replicas.
	BaseEnvs      bool = false
	CVfile        string
	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           //
	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.
)
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])
		if modules.Variables == nil {
			vars := MergeVars(
				mg.GetVars(),
				OverrideVars(mg.GetVars()))
			modules.Variables = vars
		}
		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:", 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)
		}

		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])
		if modules.Variables == nil {
			vars := MergeVars(
				mg.GetVars(),
				OverrideVars(mg.GetVars()))
			modules.Variables = vars
		}
	},
}
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: Banner + `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 MergeSourceVars added in v0.0.18

func MergeSourceVars(base metagraf.MGVars, override map[string]string) metagraf.MGVars

Used in parsing cvfile

func MergeVars

func MergeVars(base metagraf.MGVars, override map[string]string) metagraf.MGVars

func OverrideVars

func OverrideVars(keys metagraf.MGVars) map[string]string

Returns a map of key, value pairs of addressable fields in a metaGraf specification from Environment, --cvfile argument and --cvars argument.

Precedence is:

  1. --cvars argument
  2. --cvfile argument
  3. Environment

func VarsFromCmd

func VarsFromCmd(mgv metagraf.MGVars) map[string]string

Returns a map of key, value pairs that matched addressable fields in a metaGraf specification from --cvars argument.

func VarsFromFile added in v0.0.19

func VarsFromFile(mgv metagraf.MGVars) map[string]string

Returns a map of key, value pairs that matched addressable fields in a metaGraf specification from a properties file generated by "mg generate properties" and provided through the --cvfile argument.

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

func VarsFromEnv

func VarsFromEnv(mgv metagraf.MGVars) EnvVars

Builds and returns a EnvVars{} map of shell environment variables that matches addressable fields in a metaGraf specification.

Jump to

Keyboard shortcuts

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