cli

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

README

CLI Package

The CLI package provides a CLI interface for Gofer used to interact and manipulate the Gofer service. It's written with Cobra.

The most confusing part of this package is how global flags are handled. The intention for global flags is that are controllable by config, envvar, and user flags. The intended user experience here is for the user the be able to specify flags and envvars on the fly when working with the CLI, but if they have a setting they'd like to keep for every CLI action then they have the ability to specify that setting permanently in a configuration file. This model adheres to the 12-factor philosophy with a slight tweak for local usage vs app usage.

To do this:

  1. First we start out by adding a new PersistentGlobalFlag to the RootCmd struct. This tells the CLI that it should support a new global flag.
  2. We then define the global variable in the config package, this includes the variable in the structure that all CLI commands read from.
  3. We then define it's default value(if any) in the related Default*Config function.
  4. This gives us the ability to call the Init*Config function which first reads from the configuration file(if found), and then the environment(and overwrites in that order if duplicate keys are found).
  5. Lastly we call our global flag and if the user has set it we overwrite whatever is current in the state config.

This makes it so that each command line instance can call InitState and have a proper hierarchy of variable overwriting.

The hierarchy is: config -> envvar -> flag. With each overwriting the previous one if they keys conflict. That is to say, if a user defines an option in their configuration file and then uses a flag that controls that option the flag's value will be respected and the config's value will be ignored.

Documentation

Overview

Package cli controls the main user entry point into both the API and interacting with it. It provides not only administrators an easy way to interact with gofer, but is the main entry point for how non-UI users interact with Gofer.

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "gofer",
	Short: "Gofer is a distributed, continuous thing do-er.",
	Long: `Gofer is a distributed, continuous thing do-er.

It uses a similar model to concourse(https://concourse-ci.org/), leveraging the docker container as a key mechanism
to run short-lived workloads. The benefits of this is simplicity. No foreign agents, no cluster setup, just run
containers.

Read more at https://clintjedwards.com/gofer
`,
	Version: " ",
	PersistentPreRun: func(cmd *cobra.Command, _ []string) {
		cl.InitState(cmd)
	},
}

RootCmd is the base of the cli

Functions

func Execute

func Execute() error

Execute adds all child commands to the root command and sets flags appropriately.

Types

This section is empty.

Directories

Path Synopsis
Package cl contains global variables used across the cli package.
Package cl contains global variables used across the cli package.

Jump to

Keyboard shortcuts

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