gadgets

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const GOGOIMPORTPATH = "github.com/2bit-software/gogo/pkg/gogo"
View Source
const MAIN_FILENAME = "main.gogo.go"
View Source
const (
	REQUIRED_VERSION = "v1.24.0"
)

Variables

View Source
var (
	HELLO_TEMPLATE          = template.New("hello.go.tmpl")
	HELLO_PKG_TEMPLATE      = template.New("hello.pkg.go.tmpl")
	HELLO_PKG_TEST_TEMPLATE = template.New("hello_test.pkg.go.tmpl")
)

Functions

func Build

func Build(log *log.Logger, buildOpts BuildOpts) error

Build reads all the gogo files in the directory, applies their configuration options, and builds the resulting binary. The buildDir is the directory in which we are building the source FROM. The output of the binary can be specified in the buildOpts.OutputFilepath

func BuildFuncList

func BuildFuncList(opts RunOpts, dir string) ([]function, error)

BuildFuncList builds a list of functions that can be run. It combines both local and global functions. If there are name collisions, the local one takes precedence, and the global one can be used with a prefix. e.g. `gogo g:funcName` would run the global function `funcName`

func BuildGlobal

func BuildGlobal(opts RunOpts) error

func BuildLocal

func BuildLocal(opts RunOpts) error

BuildLocal searches for the local gogo files, and builds the binary

func GenerateMainFile

func GenerateMainFile(opts RunOpts) error

Generate the main output file

func GetPlainType

func GetPlainType(field *ast.Field) string

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

func Init

func Init(folder, goModPath string) error

Init a new GoGo project. It's assumed the folder is the full path to what should be made and where the files should be places. The gogoModPath is the go.mod module path to use.

func Run

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

Run this is a simplified version of the Run function in cmd/gogo/main.go For now it only searches for the local gogo files, and does not try to determine if the function exists in the global cache.

func ShowFuncList

func ShowFuncList(opts RunOpts) (int, error)

ShowFuncList lists all the available functions in the local and global namespaces

Types

type BuildOpts

type BuildOpts struct {
	KeepArtifacts  bool   `json:"GOGO_KEEP_ARTIFACTS"` // When true, keeps the artifacts after the build. This includes the go src and the built binary
	DisableCache   bool   `json:"GOGO_DISABLE_CACHE"`  // When true, forces a rebuild of the binary
	Optimize       bool   `json:"GOGO_OPTIMIZE"`       // should the functions be compiled with optimization flags during this run
	BinaryFilepath string `json:"GOGO_OUTPUT"`         // the output location of the binary. If this is provided, then we don't calculate the filename or the location
	// The below properties are calculated by the build process
	SourceDir          string // the location of the directory where we are currently building the source
	OutputDir          string // the output location of the binaries
	OriginalWorkingDir string // the original working directory
}

type GoCmd

type GoCmd struct {
	Name           string // Name of the command
	Short          string // Short Description of the command. Comes from the comment, unless overridden.
	Long           string // Long Description of the command. This comes from the comment, if it exists.
	Example        string // An example of using this command
	GoFlags        []GoFlag
	ErrorReturn    bool // If true, the command returns an error
	UseGoGoContext bool // If true, the command uses the gogo context
}

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            byte   // short name of the flag
	Default          any    // default value of the flag.
	HasDefault       bool   // if true, use the default value
	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 {
	BuildOpts
	Verbose          bool   `json:"GOGO_VERBOSE"`           // output verbose information when RUNNING gogo AND the sub-command
	GlobalSourceDir  string `json:"GOGO_GLOBAL_SOURCE_DIR"` // the global location for gogo functions
	GlobalBinDir     string `json:"GOGO_GLOBAL_BIN_DIR"`    // the output location for global binaries
	BuildLocalCache  bool   `json:"GOGO_BUILD_LOCAL"`       // When true, builds the local cache and exits
	BuildGlobalCache bool   `json:"GOGO_BUILD_GLOBAL"`      // When true, builds the global cache and exits
	ScreenWidth      int    // the width of the screen, if we know
	// contains filtered or unexported fields
}

func (RunOpts) GetLogger

func (ro RunOpts) GetLogger() *log.Logger

Jump to

Keyboard shortcuts

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