gogo

package module
v0.0.0-...-2392c82 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

README

Flags

  • --build-global, -b: builds the global binaries as specified in config(s) or default search paths
  • --individual-files, -i: builds each function as separate binary - builds and exits, no function is run
  • --config, -c: specify a configuration file to use. searches common locations by default. XDG_CONFIG_HOME, GOGO_CONFIG, etc
  • --verbose, v: print verbose output
  • --shell-completions=[bash|zsh|fish|powershell]: generate shell completions for the specified shell
  • --optimize: output binar(y|ies) are stripped of debug information (this and --delve are mutually exclusive)
  • --version: print the version of this gogo
  • --autocomplete=: output the binary and base command to use for the rest of the autocompletion.

TODO:

  • We should audit that none of the variables/inputs are reserved keywords
  • or rename the inputs under the hood so they don't collide with reserved keywords
  • Allow a configuration setting that sets a prefix for all variables.
  • Provide some option so that the generated main file is not deleted
  • Same with resulting binaries
  • Support functions that have error returns, handle the result, and do something with it

Credits

Documentation

Index

Constants

View Source
const GOGOIMPORTPATH = "github.com/3b-tools/gogo"
View Source
const MAIN_FILENAME = "main.gogo.go"

Variables

This section is empty.

Functions

func Build

func Build(log *log.Logger, optimize bool, inputDir, outputFilepath string) error

Build reads all the gogo files in the directory, applies their configuration options, and builds the resulting binary.

func BuildMain

func BuildMain(log *log.Logger, inputDir, filePath string) error

BuildMain reads all the gogo files in the directory, applies their configuration options, and builds the resulting main file.

func GenerateShellCompletion

func GenerateShellCompletion(shell string, cmd *cobra.Command) error

TODO: we need to write our own versions of these, but for now...

func GetPlainType

func GetPlainType(field *ast.Field) string

GetPlainType takes an *ast.Field and returns a plain-English type description

func GetValidTargets

func GetValidTargets(dir string) []string

GetValidTargets determines the collection of available functions in the directory, plus the global functions

func Run

func Run(opts RunOpts, args []string) error

Run expects that a function should be run. For functions where building or just searching is required, other functions should be used.

Types

type Argument

type Argument interface {
	Long(string) Argument // Override the argument name in auto-complete and arguments when calling this function. Defaults to the name of the argument.
	Short(byte) Argument  // The short character for the argument
	Default(any) Argument
	Help(string) Argument
	AllowedValues(...any) Argument
	RestrictedValues(...any) Argument
	Description(string) Argument // The short description of the argument.
	Argument(any) Argument       // Start describing a different argument.
}

type Context

type Context interface {
	stdContext.Context
	SetDescription(string) Context     // This becomes the short description of the command.
	SetLongDescription(string) Context // The becomes the long description of the command. This is normally inferred from the comment of the function.
	Example(string) Context            // What would this go to?
	Argument(any) Argument
}

type GoCmd

type GoCmd struct {
	Name    string // Name of the command
	Short   string // Short Description of the command
	Long    string // Long Description of the command
	Example string // An example of using this command
	GoFlags []GoFlag
}

type GoFlag

type GoFlag struct {
	Type             string // string, int, bool, float64  This type is inferred from reading the code.
	Name             string // name of the flag
	Short            string // short name of the flag
	Default          any    // default value of the flag
	Help             string // help text for the flag
	AllowedValues    []any  // if provided, only these values are allowed, and are auto-completed in the shell
	RestrictedValues []any  // if provided, prohibits this flag from being set to these values. Panics if detected.
}

type RunOpts

type RunOpts struct {
	Verbose            bool   `json:"GOGO_VERBOSE"`             // output verbose information when RUNNING gogo AND the sub-command
	Optimize           bool   `json:"GOGO_OPTIMIZE"`            // should the functions be compiled with optimization flags during this run
	GlobalDir          string `json:"GOGO_GLOBAL_DIR"`          // the global location for gogo functions
	IndividualBinaries bool   `json:"GOGO_INDIVIDUAL_BINARIES"` // When true, each function results in a binary of the same name
}

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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