Documentation
¶
Overview ¶
package sourcerer sources CLI commands in a shell environment. See the `main` function in github.com/leep-frog/command/examples/source.go for an example of how to define a source file that uses this.
Index ¶
- Constants
- Variables
- func AliasSourcery(goExecutable string, as ...*Aliaser) []string
- func ExecutableFileGetProcessor() *commander.GetProcessor[string]
- func FileStringFromCLI(cli string) string
- func FileStringFromCLIZSH(cli string) string
- func RunCLI(cli CLI) int
- func Source(targetName string, clis []CLI, opts ...Option) int
- func StubExecutableFile(t *testing.T, filepath string, err error)
- func ValueByOS[T any](values map[string]T) T
- type Aliaser
- type AliaserCommand
- type CLI
- type Debugger
- type GoLeep
- type OS
- type Option
- type UpdateLeepPackageCommand
Constants ¶
const ( AutocompleteBranchName = "autocomplete" GenerateAutocompleteSetupBranchName = "generate-autocomplete-setup" ExecuteBranchName = "execute" ListBranchName = "listCLIs" SourceBranchName = "source" UsageBranchName = "usage" BuiltInCommandParameter = "builtin" )
const (
ExecutableFileGetProcessorName = "GO_EXECUTABLE_FILE"
)
const (
// RootDirectoryEnvVar is the directory in which all artifact files needed will be created and stored.
RootDirectoryEnvVar = "COMMAND_CLI_OUTPUT_DIR"
)
Variables ¶
var ( CurrentOS = func() OS { curOS, ok := os.LookupEnv("COMMAND_CLI_OS_OVERRIDE") if !ok { curOS = runtime.GOOS } for _, os := range oses { if os.Name() == curOS { return os } } panic(fmt.Sprintf("Unsupported leep-frog/command os: %q", curOS)) }() )
var ( // NosortString returns the complete option to ignore sorting. // It returns nothing if the IGNORE_NOSORT environment variable is set. NosortString = func() string { if _, ignore := os.LookupEnv("IGNORE_NOSORT"); ignore { return "" } return "-o nosort" } )
var (
RelevantPackages = []string{
"cd",
"command",
"gocli",
"grep",
"qmkwrapper",
"replace",
"sourcecontrol",
}
)
Functions ¶
func AliasSourcery ¶
AliasSourcery outputs all alias source commands to the provided `command.Output`.
func ExecutableFileGetProcessor ¶
func ExecutableFileGetProcessor() *commander.GetProcessor[string]
ExecutableFileGetProcessor returns a `commander.GetProcessor` that sets and gets the full go executable file path.
func FileStringFromCLI ¶
FileStringFromCLI returns a bash command that retrieves the binary file that is actually executed for a leep-frog-generated CLI.
func FileStringFromCLIZSH ¶
func RunCLI ¶
RunCLI runs an individual CLI, thus making the go executable file the only setup needed.
func StubExecutableFile ¶
StubExecutableFile stubs the executable file returned by ExecutableFileGetProcessor()
Types ¶
type AliaserCommand ¶
type AliaserCommand struct {
// contains filtered or unexported fields
}
AliaserCommand creates an alias for another arg
func (*AliaserCommand) Changed ¶
func (*AliaserCommand) Changed() bool
func (*AliaserCommand) Name ¶
func (*AliaserCommand) Name() string
func (*AliaserCommand) Node ¶
func (ac *AliaserCommand) Node() command.Node
func (*AliaserCommand) Setup ¶
func (*AliaserCommand) Setup() []string
type CLI ¶
type CLI interface { // Name is the name of the alias command to use for this CLI. Name() string // Node returns the command node for the CLI. This is where the CLI's logic lives. Node() command.Node // Changed indicates whether or not the CLI has changed after execution. // If true, the CLI's value will be save to the cache. Changed() bool // Setup describes a set of commands that will be run in bash prior to the CLI. // The output from the commands will be stored in a file whose name will be // stored in the `Data` object. See the following methods: // `Data.SetupOutputFile()` returns the file name. // `Data.SetupOutputString()` returns the file contents as a string. // `Data.SetupOutputContents()` returns the file contents as a string slice. Setup() []string }
CLI provides a way to construct CLIs in go, with tab-completion. Note, this has to be an interface (as opposed to a struct) because of the Load function.
type GoLeep ¶
type GoLeep struct{}
GoLeep is a CLI that runs command nodes that are defined in "main" packages.
type OS ¶
type OS interface { command.OS // Name is the operating system as specified by runtime.GOOS Name() string // ExecutableFileSuffix is the suffix to add for executable files (e.g. `.exe` in Windows) ExecutableFileSuffix() string // SourceableFile is the file basename to use for sourceable files (e.g. `myCLI_loader.sh` in linux) SourceableFile(target string) string // SourceSetup returns the code that should be run and/or added to a user's terminal profile // after successfully running `go run . source ...` SourceSetup(sourceableFile, targetName, goRunSourceCommand, userDir string) []string // FunctionWrap wraps the provided commands in another function. FunctionWrap(name, fn string) string // HandleAutocompleteSuccess should output the suggestions for autocomplete consumption HandleAutocompleteSuccess(command.Output, *command.Autocompletion) // HandleAutocompleteError should output error info on `Autocomplete` failure HandleAutocompleteError(output command.Output, compType int, err error) // SourceFileCommand should return the command to source the provided file. SourceFileCommand(sourcerersDir, targetName string) string // RecursiveCopyDir should return the command to recusrively copy contents from src to dst. RecursiveCopyDir(src, dst string) string // RegisterCLIs generates the code for RegisterCLIs(builtin bool, goExecutable, targetName string, cli []CLI) []string // RegisterRunCLIAutocomplete generates the shell code to source to set up // autocomplete for the provided alias. RegisterRunCLIAutocomplete(goExecutable, alias string) []string // RegisterAliasers GlobalAliaserFunc(goExecutable string) []string VerifyAliaser(*Aliaser) []string RegisterAliaser(goExecutable string, a *Aliaser) []string }
type UpdateLeepPackageCommand ¶
type UpdateLeepPackageCommand struct{}
UpdateLeepPackageCommand is a CLI for updating github.com/leep-frog packages
func (*UpdateLeepPackageCommand) Changed ¶
func (*UpdateLeepPackageCommand) Changed() bool
func (*UpdateLeepPackageCommand) Name ¶
func (*UpdateLeepPackageCommand) Name() string
func (*UpdateLeepPackageCommand) Node ¶
func (*UpdateLeepPackageCommand) Node() command.Node
func (*UpdateLeepPackageCommand) Setup ¶
func (*UpdateLeepPackageCommand) Setup() []string