command

package
v1.7.11 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const VERSION = "0.1.0"

VERSION is the semantic version.

Variables

View Source
var Action = func(c *cli.Context) error {
	if !c.Args().Present() {
		return fmt.Errorf("Enter a subprocess to run")
	}

	commandArgs := &Options{
		Args:        c.Args(),
		Environment: c.String("environment"),
		Filepath:    c.String("f"),
		YamlInline:  c.String("yaml"),
		Provider:    c.String("provider"),
		Subs:        convertSubsToMap(c.StringSlice("D")),
		Debug:       c.Bool("debug"),
	}
	if !commandArgs.Debug {
		commandArgs.Debug = (os.Getenv("SUMMON_DEBUG") == "true")
	}

	if commandArgs.Provider == "" {
		commandArgs.Provider = os.Getenv("SUMMON_PROVIDER")
	}

	var err error
	var subcommand *Subcommand

	if subcommand, err = parseCommandArgsToSubcommand(commandArgs); err != nil {
		return err
	}

	subcommand.Stdout = c.App.Writer
	return subcommand.Run()
}

Action is the main entry point for the CLI command.

View Source
var Flags = []cli.Flag{
	cli.StringFlag{
		Name:  "e, environment",
		Usage: "Specify section/environment to parse from secrets.yaml.",
	},
	cli.StringFlag{
		Name:  "provider, p",
		Usage: "Name of the provider to use. May also be specified via SUMMON_PROVIDER environment variable.",
	},
	cli.StringFlag{
		Name:  "f",
		Value: "secrets.yml",
		Usage: "Path to secrets.yml.",
	},
	cli.StringSliceFlag{
		Name:  "D",
		Value: &cli.StringSlice{},
		Usage: "var=value causes substitution of value to $var.",
	},
	cli.StringFlag{
		Name:  "yaml",
		Usage: "secrets.yml as a literal string.",
	},
	cli.BoolFlag{
		Name:  "debug, d",
		Usage: "Print debug info during program execution. . May also be specified via SUMMON_DEBUG=true environment variable.",
	},
}

Flags is a list of command-line options.

Functions

func RunCLI

func RunCLI(args []string, writer io.Writer) error

RunCLI defines and runs the command line program.

Types

type Options

type Options struct {
	Args        []string
	Filepath    string
	YamlInline  string
	Provider    string
	Subs        map[string]string
	Environment string
	Debug       bool
}

Options contains the CLI arguments parsed by the cli framework.

type Subcommand

type Subcommand struct {
	Args        []string
	SecretsMap  secretsyml.SecretsMap
	TempFactory *TempFactory
	Provider    plugin_v1.Provider

	// Set this to an io.Writer to capture stdout from the child process.
	// By default, the child process stdout goes to this process' stdout.
	Stdout io.Writer
}

Subcommand defines the input needed to run Summon.

func (*Subcommand) Run

func (sc *Subcommand) Run() (err error)

Run encapsulates the logic of Action without cli Context for easier testing

type TempFactory

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

TempFactory creates new temp files, using heuristics to choose as secure a location as possible.

func NewCustomTempFactory

func NewCustomTempFactory(path string, sharedMemoryDir string) TempFactory

NewCustomTempFactory creates a new temporary file factory with specified sharedMemoryDir. If sharedMemoryDir is empty, we use the default path for it. defer Cleanup() if you want the files removed.

func NewTempFactory

func NewTempFactory(path string) TempFactory

NewTempFactory creates a new temporary file factory. defer Cleanup() if you want the files removed.

func (*TempFactory) Cleanup

func (tf *TempFactory) Cleanup()

Cleanup removes the temporary files created with this factory.

func (*TempFactory) Push

func (tf *TempFactory) Push(value string) (string, error)

Push creates a temp file with given value. Returns the path.

Jump to

Keyboard shortcuts

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