cmd

package
v0.0.0-...-215933a Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "converge"

Name describes the name for packaging

View Source
const Version = "0.2.0"

Version describes the version for packaging

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   Name,
	Short: Name + " applies changes to systems over a graph",
	Long: Name + ` is a tool that reads modules files (see the samples directory
in the source) and applies their actions to a system.

The workflow generally looks like this:

1. write your module files
2. see what changes will happen with "converge plan yourfile.hcl"
3. apply the changes with "converge apply yourfile.hcl"

You can also visualize the execution graph with "converge graph yourfile.hcl" -
see "converge graph --help" for more details.`,

	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		level, err := cmd.Flags().GetString("log-level")
		if err != nil {
			return err
		}

		parsedLevel, err := log.ParseLevel(level)
		if err != nil {
			return err
		}

		log.SetLevel(parsedLevel)

		nocolor, err := cmd.Flags().GetBool("nocolor")
		if err != nil {
			return err
		}

		log.SetFormatter(&logging.Formatter{
			DisableColors: nocolor,
		})

		sub := cmd
		subFlags := args

		for {
			log.WithField("command", sub.Name()).Debug("registering flags")

			if err := viper.BindPFlags(sub.Flags()); err != nil {
				return errors.Wrapf(err, "failed to bind flags for %s", sub.Name())
			}
			if err := viper.BindPFlags(sub.PersistentFlags()); err != nil {
				return errors.Wrapf(err, "failed to bind persistent flags for %s", sub.Name())
			}

			potentialSub, potentialSubFlags, err := sub.Find(subFlags)
			if err != nil {
				return errors.Wrapf(err, "failed to get child for %s", sub.Name())
			}

			if sub == potentialSub {
				break
			}

			sub = potentialSub
			subFlags = potentialSubFlags
		}

		return nil
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func GracefulExit

func GracefulExit(cancel context.CancelFunc)

GracefulExit traps interrupt signals for a graceful exit

func GracefulExitBlocking

func GracefulExitBlocking(cancel context.CancelFunc)

GracefulExitBlocking handles graceful exits, and blocks until exit

func UseColor

func UseColor() bool

UseColor tells us whether or not to print colors using ANSI escape sequences based on the following: 1. If we're in a color terminal 2. If the user has specified the `nocolor` option (deduced via Viper) 3. If we're on Windows.

Types

This section is empty.

Jump to

Keyboard shortcuts

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