cmd

package
v0.0.0-...-02c76fb Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 46 Imported by: 3

Documentation

Index

Constants

View Source
const Name = "converge"

Name describes the name 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

View Source
var Version = "unset"

Version is pulled from git during a build

Functions

func CanUseEscapeSequences

func CanUseEscapeSequences() bool

CanUseEscapeSequences 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.

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

Types

type TimerDisplay

type TimerDisplay struct {
	// contains filtered or unexported fields
}

TimerDisplay displays timing for incremental updates, like plan and apply

func (*TimerDisplay) AddTimer

func (td *TimerDisplay) AddTimer(name string)

AddTimer starts a timer display for the given name

func (*TimerDisplay) Bypass

func (td *TimerDisplay) Bypass() io.Writer

Bypass provides an io.Writer that can write without interfering with this display

func (*TimerDisplay) Message

func (td *TimerDisplay) Message() string

Message creates the current message to display

func (*TimerDisplay) RemoveTimer

func (td *TimerDisplay) RemoveTimer(name string)

RemoveTimer removes a timer display for the given name

func (*TimerDisplay) Start

func (td *TimerDisplay) Start()

Start starts the display

func (*TimerDisplay) Stop

func (td *TimerDisplay) Stop()

Stop stops the display

Jump to

Keyboard shortcuts

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