gear

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 28 Imported by: 0

README

gear

Gear provides the generation of GUIs and interactive CLIs for any existing command line tools

Documentation

Overview

Package gear provides the generation of GUIs and interactive CLIs for any existing command line tools.

Index

Constants

This section is empty.

Variables

View Source
var AppType = gti.AddType(&gti.Type{Name: "cogentcore.org/cogent/gear.App", IDName: "app", Doc: "App is a GUI view of a gear command.", Embeds: []gti.Field{{Name: "Frame"}}, Fields: []gti.Field{{Name: "Cmd", Doc: "Cmd is the root command associated with this app."}, {Name: "CurCmd", Doc: "CurCmd is the current root command being typed in."}, {Name: "Dir", Doc: "Dir is the current directory of the app."}}, Instance: &App{}})

AppType is the gti.Type for App

Functions

func StructForFlags

func StructForFlags(flags []*Flag) any

StructForFlags returns a new struct object for the given flags.

Types

type App

type App struct {
	gi.Frame

	// Cmd is the root command associated with this app.
	Cmd *Cmd

	// CurCmd is the current root command being typed in.
	CurCmd string

	// Dir is the current directory of the app.
	Dir string
}

App is a GUI view of a gear command.

func NewApp

func NewApp(par ki.Ki, name ...string) *App

NewApp adds a new App with the given name to the given parent: App is a GUI view of a gear command.

func (*App) AppBar

func (a *App) AppBar(tb *gi.Toolbar)

func (*App) Config added in v0.0.1

func (a *App) Config()

func (*App) KiType

func (t *App) KiType() *gti.Type

KiType returns the *gti.Type of App

func (*App) New

func (t *App) New() ki.Ki

New returns a new *App value

func (*App) OnInit

func (a *App) OnInit()

func (*App) RunCmd

func (a *App) RunCmd(cmd string, cmds *gi.Frame, dir *gi.Label) error

RunCmd runs the given command in the context of the given commands frame and current directory label.

func (*App) SetCmd

func (t *App) SetCmd(v *Cmd) *App

SetCmd sets the [App.Cmd]: Cmd is the root command associated with this app.

func (*App) SetCurCmd

func (t *App) SetCurCmd(v string) *App

SetCurCmd sets the [App.CurCmd]: CurCmd is the current root command being typed in.

func (*App) SetDir

func (t *App) SetDir(v string) *App

SetDir sets the [App.Dir]: Dir is the current directory of the app.

func (*App) SetStackTop

func (t *App) SetStackTop(v int) *App

SetStackTop sets the [App.StackTop]

func (*App) SetTooltip

func (t *App) SetTooltip(v string) *App

SetTooltip sets the [App.Tooltip]

type Cmd

type Cmd struct {
	// Cmd is the actual name of the command (eg: "git", "go build")
	Cmd string
	// Name is the formatted name of the command (eg: "Git", "Go build")
	Name string
	// Doc is the documentation for the command (eg: "compile packages and dependencies")
	Doc string
	// Flags contains the flags for the command
	Flags []*Flag
	// Cmds contains the subcommands of the command
	Cmds []*Cmd
}

Cmd contains all of the data for a parsed command line command.

func NewCmd

func NewCmd(cmd string) *Cmd

NewCmd makes a new App object from the given command name. It does not parse it; see [App.Parse].

func (*Cmd) GetBlocks

func (cm *Cmd) GetBlocks() ([]ParseBlock, error)

GetBlocks gets the ParseBlock objects for this command.

func (*Cmd) GetHelp

func (cm *Cmd) GetHelp() (string, error)

GetHelp gets the help information for the command. It tries various different commands and flags to get the help information and only returns an error if all of them fail.

func (*Cmd) Parse

func (cm *Cmd) Parse() error

Parse uses the help messages of the app to fill in its data fields.

func (*Cmd) SetFromBlocks

func (cm *Cmd) SetFromBlocks(blocks []ParseBlock) error

SetFromBlocks sets the information of the command from the given ParseBlock objects.

type Flag

type Flag struct {
	// Name is the canonical (longest) name of the flag.
	// It includes the leading dashes of the flag.
	Name string
	// Names are the different names the flag can go by.
	// They include the leading dashes of the flag.
	Names []string
	// Type is the type or value hint for the flag.
	Type string
	// Doc is the documentation for the flag.
	Doc string
}

Flag contains the information for a parsed command line flag.

type ParseBlock

type ParseBlock struct {
	Name string
	Doc  string
}

ParseBlock is a block of parsed content containing the name of something and the documentation for it.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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