godellauncher

package
v2.107.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	GodelConfigYML = "godel.yml"
)

Variables

This section is empty.

Functions

func CobraCmdToRootCmd

func CobraCmdToRootCmd(cmd *cobra.Command) *cobra.Command

CobraCmdToRootCmd takes the provided *cobra.Command and returns a new *cobra.Command that acts as its "root" command. The root command has "godel" as its command name and is configured to silence the built-in Cobra error printing. However, it has custom logic to match the standard Cobra error output for unrecognized flags.

func ConfigDirPath

func ConfigDirPath(projectDirPath string) (string, error)

ConfigDirPath returns the path to the gödel configuration directory given the path to the project directory. Returns an error if the directory structure does not match what is expected.

func ListProjectPaths

func ListProjectPaths(projectDir string, include, exclude matcher.Matcher) ([]string, error)

ListProjectPaths lists all of the paths in the provided project directory that matches the provided include matcher and does not match the provided exclude matcher. The paths are relative to the current working directory.

func UnknownCommandError

func UnknownCommandError(cmd *cobra.Command, args []string) error

func UsageString

func UsageString(tasks []Task) string

UsageString returns the usage string for the launcher application with the specified tasks. The returned string does not have a trailing newline.

Types

type FlagType

type FlagType int

FlagType represents the type of a flag (string, boolean, etc.). Currently only string flags are supported.

const (
	StringFlag FlagType = iota
	BoolFlag
)

type GlobalConfig

type GlobalConfig struct {
	// Path to the gödel executable
	Executable string
	// The value of the "--wrapper" flag provided to the gödel invocation.
	Wrapper string
	// True if the "--debug" flag was provided to the gödel invocation.
	Debug bool
	// True if the "--version" flag was provided to the gödel invocation.
	Version bool
	// True if the "--help" or "-h" flag was provided to the gödel invocation.
	Help bool
	// The first non-flag argument provided to the gödel executable. This is the task name.
	Task string
	// All of the arguments following the "Task" argument that was provided to the gödel executable.
	TaskArgs []string
}

GlobalConfig stores the configuration provided to the initial invocation of gödel.

func ParseAppArgs

func ParseAppArgs(args []string) (GlobalConfig, error)

ParseAppArgs parses the arguments provided to the gödel launcher application into a GlobalConfig struct. Returns an error if the provided arguments are not legal. The provided args should be the arguments provided in os.Args. The arguments should match the following form:

[executable] [<global flags>] [<task>] [<task flags/args>]

<global flags> can be one of [--version], [--help|-h], [--debug] or [--wrapper <path>]. Note that, unlike the behavior of some other CLI programs, the flags can only be specified exactly as described: for example, inputs of the form "--version=true", "--debug false" and "--wrapper=<path>" are not valid.

func (GlobalConfig) ProjectDir

func (g GlobalConfig) ProjectDir() (string, error)

ProjectDir returns the project directory for the global configuration. Returns an error if the wrapper path was not specified.

type GlobalFlagOptions

type GlobalFlagOptions struct {
	// DebugFlag is the flag that is passed to the plugin when "debug" mode is true (for example, "--debug"). If empty,
	// indicates that the plugin does not support a "debug" mode. The value should include any leading hyphens (this
	// allows for specifying long or short-hand flags).
	DebugFlag string
	// ProjectDirFlag is the flag that is passed to the plugin for the project directory (for example, "--project-dir").
	// If this value is non-empty, then the arguments "<ProjectDirFlag> <projectDirPath>" will be provided to the
	// plugin. If empty, indicates that the plugin does not support a project directory flag. The value should include
	// any leading hyphens (this allows for specifying long or short-hand flags).
	ProjectDirFlag string
	// GodelConfigFlag is the flag that is passed to the plugin for the godel configuration file (for example,
	// "--godelConfig"). If this value is non-empty, then the arguments "<GodelConfigFlag> <godelConfigFilePath>" will
	// be provided to the plugin. If empty, indicates that the plugin does not support a godel config flag. The value
	// should include any leading hyphens (this allows for specifying long or short-hand flags).
	GodelConfigFlag string
	// ConfigFlag is the flag that is passed to the plugin for the configuration file (for example, "--config"). If this
	// value is non-empty, then the arguments "<ConfigFlag> <configFilePath>" will be provided to the plugin. If empty,
	// indicates that the plugin does not support a config flag. The value should include any leading hyphens (this
	// allows for specifying long or short-hand flags).
	ConfigFlag string
}

type PluginsParam

type PluginsParam struct {
	DefaultResolvers []artifactresolver.Resolver
	Plugins          []SinglePluginParam
}

type Task

type Task struct {
	// The name of the command. This is used as the task command for invocation and should not contain any whitespace.
	Name string

	// The description for this task. Should be suitable to use as the command description in CLI help.
	Description string

	// The name of the configuration file for the task ("task.yml", etc.). Can be blank if the task does not require
	// file-based configuration.
	ConfigFile string

	// Configures the manner in which the global flags are processed.
	GlobalFlagOpts GlobalFlagOptions

	// Verify stores the option for the "--verify" task. If non-nil, this command is run as part of the "verify" task.
	Verify *VerifyOptions

	// The runner that is invoked to run this task. Should be possible to run in-process (that is, this function should
	// not call os.Exit or equivalent).
	RunImpl func(t *Task, global GlobalConfig, stdout io.Writer) error
}

func CobraCLITask

func CobraCLITask(cmd *cobra.Command, globalConfigPtr *GlobalConfig) Task

CobraCLITask creates a new Task that runs the provided *cobra.Command. The runner for the task does the following:

  • Creates a "dummy" root cobra.Command with "godel" as the command name
  • Adds the provided command as a subcommand of the dummy root
  • Executes the root command with the following "os.Args": [executable] [task] [task args...]

The second argument is an optional pointer. If the pointer is non-nil, then the value of the provided pointer will be set to the GlobalConfig provided when the task is run.

func TaskForInput

func TaskForInput(global GlobalConfig, tasks []Task) (Task, error)

TaskForInput returns the Task that should be run based on the provided GlobalConfig.

If the "Task" field of GlobalConfig is empty, it indicates that the launcher was run without any tasks specified. If that is the case, the following logic is used to determine the task to be returned:

* If global.Help is true, the help output is printed * If global.Help is false and global.Version is true, the version is printed * If global.Help and global.Version are both false, the help output is printed

If the "Task" field of GlobalConfig is non-empty, then the task in the provided "tasks" slice with the name that matches the "Task" field is returned.

Returns an error if the "Task" field is non-empty but there is no corresponding task in the "tasks" slice, or if the provided "tasks" slice contains multiple entries with the same name.

func (*Task) Run

func (t *Task) Run(global GlobalConfig, stdout io.Writer) error

type TasksConfigProvidersParam

type TasksConfigProvidersParam struct {
	DefaultResolvers []artifactresolver.Resolver
	ConfigProviders  []artifactresolver.LocatorWithResolverParam
}

type UpgradeConfigTask

type UpgradeConfigTask struct {
	// The ID for the task. Should be of the form "groupID:productID" ("com.palantir.godel:godel",
	// "com.palantir.format-plugin:format-plugin", etc.).
	ID string

	// The name of the configuration file for the task ("godel.yml", "check-plugin.yml" etc.).
	ConfigFile string

	// The name of the legacy configuration file for the task. Blank if none exists.
	LegacyConfigFile string

	// Configures the manner in which the global flags are processed.
	GlobalFlagOpts GlobalFlagOptions

	// The runner that is invoked to run this config upgrade task. Takes the provided input config bytes and returns the
	// upgraded configuration bytes. If the provided config bytes are a valid representation of configuration for the
	// most recent version, the returned bytes should be the same as the input. Should be possible to run in-process
	// (that is, this function should not call os.Exit or equivalent).
	RunImpl func(t *UpgradeConfigTask, global GlobalConfig, configBytes []byte, stdout io.Writer) ([]byte, error)
}

func (*UpgradeConfigTask) Run

func (t *UpgradeConfigTask) Run(configBytes []byte, global GlobalConfig, stdout io.Writer) ([]byte, error)

type VerifyFlag

type VerifyFlag struct {
	Name        string
	Description string
	Type        FlagType
}

func (VerifyFlag) AddFlag

func (f VerifyFlag) AddFlag(fset *pflag.FlagSet) (interface{}, error)

AddFlag adds the flag represented by VerifyFlag to the specified pflag.FlagSet. Returns the pointer to the value that can be used to retrieve the value.

func (VerifyFlag) ToFlagArgs

func (f VerifyFlag) ToFlagArgs(flagVal interface{}) ([]string, error)

ToFlagArgs takes the input parameter (which should be the value returned by calling AddFlag for the receiver) and returns a string slice that reconstructs the flag arguments for the given flag.

type VerifyOptions

type VerifyOptions struct {
	// VerifyTaskFlags stores the task-specific flags supported by this verify task.
	VerifyTaskFlags []VerifyFlag
	// Ordering stores the weighting/ordering of the task as it will be run in the verify task.
	Ordering int
	// ApplyTrueArgs specifies the arguments (typically flags) that should be provided to the verify task when "apply"
	// mode is true: for example, []string{"--apply"}. May be nil/empty.
	ApplyTrueArgs []string
	// ApplyFalseArgs specifies the arguments (typically flags) that should be provided to the verify task when "apply"
	// mode is false: for example, []string{"--verify"} or []string{"-l"}.. May be nil/empty.
	ApplyFalseArgs []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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