entry

package
v0.0.0-...-328360e Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package entry provides an API to kicking off the initial binary execution. The functions and data structures in this library can be used to package your own custom entry point as a custom application. TODO: Should this be nested inside of lang/ or can it be used for all GAPI's?

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, data *Data)

Register takes a data struct and stores a reference to it in our entry system along with a name. Future lookups to that name will pull out that data. Register is commonly called in the init() method of the module that defined it, which happens at program startup. Build flags should be used to determine which Register functions should run. Multiple entry data struct can be registered at a time. There is no matching Unregister function at this time.

Types

type Customizable

type Customizable interface {
	// Customize takes in the full parsed struct, and returns the RunArgs
	// that we should use for the run operation.
	// TODO: should the input type be *cli.RunArgs instead?
	Customize(runArgs interface{}) (*cli.RunArgs, error)
}

Customizable is an additional API you can implement to have tighter control over how the entry executes mgmt. TODO: add an API with: func(arg.Config) (*arg.Parser, error) ?

type Data

type Data struct {
	// Program is the name of this program, usually set at compile time.
	Program string

	// Version is the version of this program, usually set at compile time.
	Version string

	// Debug represents if we're running in debug mode or not.
	Debug bool

	// Logf is a logger which should be used.
	Logf func(format string, v ...interface{})

	// Args is the CLI struct to use. This takes the format of the go-arg
	// API. Keep in mind that these values will be added on to the normal
	// run subcommand with frontend that is chosen. Make sure you don't add
	// anything that would conflict with that. Of note, a new subcommand is
	// probably not what you want. To do more complicated things, you will
	// need to implement a different custom API with Customizable.
	Args interface{}

	// Frontend is the name of the GAPI to run.
	Frontend string

	// Top is the initial input or code to run.
	Top []byte

	// Customizable is an additional API you can implement to have tighter
	// control over how the entry executes mgmt.
	Custom Customizable
}

Data is what a prospective standalone entry program must specify to our API.

func (*Data) Validate

func (obj *Data) Validate() error

Validate verifies that the structure has acceptable data stored within.

type Init

type Init struct {
	// Data is the original data that we get from the core compilation.
	Data *cliUtil.Data

	Debug bool
	Logf  func(format string, v ...interface{})
}

Init is some data and handles to pass in.

type Initable

type Initable interface {
	Customizable

	// Init passes in some data and handles.
	Init(*Init) error
}

Initable lets us have a way to pass in some data and handles if the struct wants them. Implementing this is optional.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner implements the complex plumbing that kicks off the run. The top-level main function should call our Run method. This is all private because it should only get returned by the Lookup method and used as-is.

func Lookup

func Lookup(name string) (*Runner, error)

Lookup takes a name and returns the runner that implements the complex plumbing to kick off the run. If one has not been registered under that name, then this will error.

func (*Runner) CLI

func (obj *Runner) CLI(ctx context.Context, data *cliUtil.Data) error

CLI is the entry point for using any embedded package from the CLI. It is used as the main entry point from the top-level main function and kicks-off the CLI parser.

XXX: This function is analogous to the cli/cli.go:CLI() function. Could it be shared with what's there already or extended to get used for the method too?

func (*Runner) Name

func (obj *Runner) Name() string

Name returns the name of the program, which should match the argv[1] of what we want to use to call this from the top-level main.

Jump to

Keyboard shortcuts

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