prep

package module
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: GPL-3.0 Imports: 21 Imported by: 13

README

This is part of 'argv'.

argv has goals for your application which are:

  • help give birth to your command
  • then help it die with grace in the end

prep currently provides:

  • bash autocompletion
  • command history
  • timing on exit
  • watchdog on exit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CHAN *log.LogFlag
View Source
var INFO *log.LogFlag
View Source
var POLL *log.LogFlag
View Source
var WARN *log.LogFlag

Functions

func AppName added in v0.0.6

func AppName() string

returns the name of the executable registered for shell autocomplete

func ArgDebug

func ArgDebug() bool

returns true if --gui-debug was passed from the command line

func ArgLogger

func ArgLogger() bool

func Debugger

func Debugger()

func DryRun added in v0.0.37

func DryRun() bool

func ExitWatchdog added in v0.0.32

func ExitWatchdog()

this code doesn't need to be this complicated. I put it here as reference code for myself so I could remember where it is.

func GetLast added in v0.0.8

func GetLast(cur string, argv []string) string

returns the last command (is blank if the current arg is not blank)

func MakeAutocompleteFiles added in v0.0.33

func MakeAutocompleteFiles(argname string)

func MakeBashCompleteFiles added in v0.0.33

func MakeBashCompleteFiles(argname string)

func MakeZshCompleteFiles added in v0.0.33

func MakeZshCompleteFiles(argname string)

func StandardVersion added in v0.0.24

func StandardVersion(ARGNAME, VERSION, BUILDTIME string) string

Types

type ArgsBash added in v0.0.3

type ArgsBash struct {
	Bash bool `arg:"--bash"                               help:"generate bash completion"`
}

type ArgsDebugger

type ArgsDebugger struct {
	Debugger bool `arg:"--debugger" help:"open the debugger window"`
	Logger   bool `arg:"--logger" help:"open the log.* control window"`
}

This struct can be used with the go-arg package

type Auto added in v0.0.8

type Auto struct {
	Ctime     *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=ctime,proto3" json:"ctime,omitempty"`           // when the user tried this autocomplete
	Duration  *durationpb.Duration   `protobuf:"bytes,2,opt,name=duration,proto3" json:"duration,omitempty"`     // time since the last autocomplete
	Argname   string                 `protobuf:"bytes,3,opt,name=argname,proto3" json:"argname,omitempty"`       // what the shell thinks the name of the executable is
	Arg0      string                 `protobuf:"bytes,4,opt,name=arg0,proto3" json:"arg0,omitempty"`             // what os.Exec() has as os.Argv[0]   // not interesting
	Arg1      string                 `protobuf:"bytes,5,opt,name=arg1,proto3" json:"arg1,omitempty"`             // should always be "--auto-complete" // not interesting
	Arg3      string                 `protobuf:"bytes,6,opt,name=arg3,proto3" json:"arg3,omitempty"`             // usually argv3 == argv0
	Argv      []string               `protobuf:"bytes,7,rep,name=argv,proto3" json:"argv,omitempty"`             // use this to store whatever you want while the whole POST happens
	Cmd       string                 `protobuf:"bytes,8,opt,name=cmd,proto3" json:"cmd,omitempty"`               // the cmd being processed. For "git pull <tab>", cmd would be "pull"
	Partial   string                 `protobuf:"bytes,9,opt,name=partial,proto3" json:"partial,omitempty"`       // set to the partial string trying to be matched
	IsAuto    bool                   `protobuf:"varint,10,opt,name=isAuto,proto3" json:"isAuto,omitempty"`       // is true if '--auto-complete' is set
	SetupAuto bool                   `protobuf:"varint,11,opt,name=setupAuto,proto3" json:"setupAuto,omitempty"` // is true if '--bash' is set // setup bash autocomplete here
	Debug     bool                   `protobuf:"varint,12,opt,name=debug,proto3" json:"debug,omitempty"`         // print debugging info if true
	Newline   bool                   `protobuf:"varint,13,opt,name=newline,proto3" json:"newline,omitempty"`     // was a newline was sent to STDERR?
	Last      string                 `protobuf:"bytes,14,opt,name=last,proto3" json:"last,omitempty"`            // the last arg
	Goargs    []string               `protobuf:"bytes,15,rep,name=goargs,proto3" json:"goargs,omitempty"`        // what to send to alex flint's go-args for help
	Fast      bool                   `protobuf:"varint,16,opt,name=fast,proto3" json:"fast,omitempty"`           // was the user fast last time?
	Fastcmd   string                 `protobuf:"bytes,17,opt,name=fastcmd,proto3" json:"fastcmd,omitempty"`      // what subcommand was the user fast on?
	// contains filtered or unexported fields
}

func Autocomplete added in v0.0.32

func Autocomplete(dest any) *Auto

func Bash added in v0.0.3

func Bash(dest any) *Auto

deprecate this

func Bash3 added in v0.0.8

func Bash3(dest any) *Auto

deprecate this

func (*Auto) Autocomplete2 added in v0.0.8

func (pb *Auto) Autocomplete2(sendthis string)

deprecate

func (*Auto) Autocomplete3 added in v0.0.12

func (pb *Auto) Autocomplete3(sendthis []string)

deprecate

func (*Auto) BadExit added in v0.0.21

func (pb *Auto) BadExit(msg string, err error)

func (*Auto) Debugf added in v0.0.8

func (pb *Auto) Debugf(fmts string, parts ...any)

decides here to print to STDERR or not

func (*Auto) Descriptor deprecated added in v0.0.8

func (*Auto) Descriptor() ([]byte, []int)

Deprecated: Use Auto.ProtoReflect.Descriptor instead.

func (*Auto) FormatJSON added in v0.0.8

func (v *Auto) FormatJSON() string

human readable JSON

func (*Auto) FormatTEXT added in v0.0.8

func (v *Auto) FormatTEXT() string

apparently this isn't stable, but it's awesomely better https://protobuf.dev/reference/go/faq/#unstable-text it's brilliant for config files!

func (*Auto) GenerateSubCommandStrings added in v0.0.32

func (pb *Auto) GenerateSubCommandStrings(cmd ...string)

try out a new name. also, this whole thing is dumb and needs to be redone

func (*Auto) GetArg0 added in v0.0.8

func (x *Auto) GetArg0() string

func (*Auto) GetArg1 added in v0.0.8

func (x *Auto) GetArg1() string

func (*Auto) GetArg3 added in v0.0.8

func (x *Auto) GetArg3() string

func (*Auto) GetArgname added in v0.0.8

func (x *Auto) GetArgname() string

func (*Auto) GetArgv added in v0.0.8

func (x *Auto) GetArgv() []string

func (*Auto) GetCmd added in v0.0.8

func (x *Auto) GetCmd() string

func (*Auto) GetCtime added in v0.0.8

func (x *Auto) GetCtime() *timestamppb.Timestamp

func (*Auto) GetDebug added in v0.0.8

func (x *Auto) GetDebug() bool

func (*Auto) GetDuration added in v0.0.8

func (x *Auto) GetDuration() *durationpb.Duration

func (*Auto) GetFast added in v0.0.32

func (x *Auto) GetFast() bool

func (*Auto) GetFastcmd added in v0.0.32

func (x *Auto) GetFastcmd() string

func (*Auto) GetGoargs added in v0.0.20

func (x *Auto) GetGoargs() []string

func (*Auto) GetIsAuto added in v0.0.8

func (x *Auto) GetIsAuto() bool

func (*Auto) GetLast added in v0.0.10

func (x *Auto) GetLast() string

func (*Auto) GetNewline added in v0.0.8

func (x *Auto) GetNewline() bool

func (*Auto) GetPartial added in v0.0.8

func (x *Auto) GetPartial() string

func (*Auto) GetSetupAuto added in v0.0.8

func (x *Auto) GetSetupAuto() bool

func (*Auto) GoodExit added in v0.0.21

func (pb *Auto) GoodExit(msg string)

func (*Auto) Marshal added in v0.0.8

func (v *Auto) Marshal() ([]byte, error)

marshal to wire. This is called winning.

func (*Auto) MarshalJSON added in v0.0.8

func (v *Auto) MarshalJSON() ([]byte, error)

marshal json

func (*Auto) PrintDebug added in v0.0.8

func (pb *Auto) PrintDebug()

print out auto complete debugging info

func (*Auto) PrintDebugNew added in v0.0.33

func (pb *Auto) PrintDebugNew(msg string)

func (*Auto) ProtoMessage added in v0.0.8

func (*Auto) ProtoMessage()

func (*Auto) ProtoReflect added in v0.0.8

func (x *Auto) ProtoReflect() protoreflect.Message

func (*Auto) Reset added in v0.0.8

func (x *Auto) Reset()

func (*Auto) SendString added in v0.0.32

func (pb *Auto) SendString(sendthis string)

the application must send a string "help run list"

func (*Auto) SendStrings added in v0.0.32

func (pb *Auto) SendStrings(parts []string)

the application must send an array []string{"help", "run", "list"}

func (*Auto) String added in v0.0.8

func (x *Auto) String() string

func (*Auto) SubCommand added in v0.0.12

func (pb *Auto) SubCommand(cmd ...string)

func (*Auto) Unmarshal added in v0.0.8

func (v *Auto) Unmarshal(data []byte) error

unmarshal from wire. You have won.

func (*Auto) UnmarshalJSON added in v0.0.8

func (v *Auto) UnmarshalJSON(data []byte) error

unmarshal json

func (*Auto) UnmarshalTEXT added in v0.0.8

func (v *Auto) UnmarshalTEXT(data []byte) error

unmarshalTEXT. This reads the .text config file back in after the user edits it

func (*Auto) Version added in v0.0.20

func (pb *Auto) Version() string

func (*Auto) WriteHelp added in v0.0.13

func (pb *Auto) WriteHelp()

todo: fix this

type AutoArgs added in v0.0.8

type AutoArgs struct {

	// hidden    bool                    // don't update the toolkits when it's hidden
	Auto func([]string) // the function for shell autocomplete

	ARGNAME   string // a good way to track the name of the binary ?
	VERSION   string
	BUILDTIME string
	// contains filtered or unexported fields
}

this is a work in progress

type AutoScanner added in v0.0.8

type AutoScanner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*AutoScanner) Next added in v0.0.8

func (it *AutoScanner) Next() *Auto

Next() returns the next thing in the array

func (*AutoScanner) Scan added in v0.0.8

func (it *AutoScanner) Scan() bool

type Autos added in v0.0.8

type Autos struct {
	Uuid     string  `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`       // `autogenpb:uuid:94210ebf-a534-4b33-aadd-2f5e1f56ae38`
	Version  string  `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v0.0.1`
	Autos    []*Auto `protobuf:"bytes,3,rep,name=autos,proto3" json:"autos,omitempty"`
	Filename string  `protobuf:"bytes,4,opt,name=filename,proto3" json:"filename,omitempty"` // `autogenpb:save` -- this enables autogenerated pb.Load() and pb.Save()
	// contains filtered or unexported fields
}

func NewAutos added in v0.0.8

func NewAutos() *Autos

func (*Autos) All added in v0.0.8

func (x *Autos) All() *AutoScanner

func (*Autos) Append added in v0.0.8

func (x *Autos) Append(y *Auto)

a Append() shortcut (that does Clone() with a mutex) notsure if it really works

func (*Autos) Clone added in v0.0.30

func (x *Autos) Clone(y *Auto) *Auto

a Clone() shortcut (with a mutex). notsure if it really works

func (*Autos) Delete added in v0.0.8

func (x *Autos) Delete(y *Auto) bool

func (*Autos) Descriptor deprecated added in v0.0.8

func (*Autos) Descriptor() ([]byte, []int)

Deprecated: Use Autos.ProtoReflect.Descriptor instead.

func (*Autos) FormatJSON added in v0.0.8

func (v *Autos) FormatJSON() string

human readable JSON

func (*Autos) FormatTEXT added in v0.0.8

func (v *Autos) FormatTEXT() string

apparently this isn't stable, but it's awesomely better https://protobuf.dev/reference/go/faq/#unstable-text it's brilliant for config files!

func (*Autos) GetAutos added in v0.0.8

func (x *Autos) GetAutos() []*Auto

func (*Autos) GetFilename added in v0.0.23

func (x *Autos) GetFilename() string

func (*Autos) GetUuid added in v0.0.8

func (x *Autos) GetUuid() string

func (*Autos) GetVersion added in v0.0.8

func (x *Autos) GetVersion() string

func (*Autos) IterAll added in v0.0.8

func (x *Autos) IterAll() iter.Seq[*Auto]

Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'

func (*Autos) Len added in v0.0.8

func (x *Autos) Len() int

func (*Autos) Load added in v0.0.23

func (pb *Autos) Load() error

func (*Autos) Marshal added in v0.0.8

func (v *Autos) Marshal() ([]byte, error)

marshal to wire. This is called winning.

func (*Autos) MarshalJSON added in v0.0.8

func (v *Autos) MarshalJSON() ([]byte, error)

marshal json

func (*Autos) PrintHistory added in v0.0.33

func (all *Autos) PrintHistory()

func (*Autos) ProtoMessage added in v0.0.8

func (*Autos) ProtoMessage()

func (*Autos) ProtoReflect added in v0.0.8

func (x *Autos) ProtoReflect() protoreflect.Message

func (*Autos) Reset added in v0.0.8

func (x *Autos) Reset()

func (*Autos) Save added in v0.0.23

func (pb *Autos) Save() error

func (*Autos) String added in v0.0.8

func (x *Autos) String() string

func (*Autos) Unmarshal added in v0.0.8

func (v *Autos) Unmarshal(data []byte) error

unmarshal from wire. You have won.

func (*Autos) UnmarshalJSON added in v0.0.8

func (v *Autos) UnmarshalJSON(data []byte) error

unmarshal json

func (*Autos) UnmarshalTEXT added in v0.0.8

func (v *Autos) UnmarshalTEXT(data []byte) error

unmarshalTEXT. This reads the .text config file back in after the user edits it

type AutosScanner added in v0.0.8

type AutosScanner struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*AutosScanner) Next added in v0.0.8

func (it *AutosScanner) Next() *Autos

Next() returns the next thing in the array

func (*AutosScanner) Scan added in v0.0.8

func (it *AutosScanner) Scan() bool

type ExitCode added in v0.0.38

type ExitCode int

ExitCode represents a program's exit status code.

const (

	// ExitSuccess indicates that the program completed its task without errors.
	ExitSuccess ExitCode = 0

	// ExitFailure is a generic, catch-all code for "something went wrong."
	// It should be used if no other more specific code applies.
	ExitFailure ExitCode = 1

	// ExitUsage indicates that the user provided invalid command-line arguments or flags.
	// (Standard: EX_USAGE)
	ExitUsage ExitCode = 64

	// ExitDataErr indicates that the input data was incorrect or malformed.
	// (e.g., a corrupt configuration file).
	// (Standard: EX_DATAERR)
	ExitDataErr ExitCode = 65

	// ExitNoInput indicates that an input file was not found or could not be read.
	// (Standard: EX_NOINPUT)
	ExitNoInput ExitCode = 66

	// ExitNoUser indicates that a specified user did not exist.
	// (Standard: EX_NOUSER)
	ExitNoUser ExitCode = 67

	// ExitNoHost indicates that a specified host did not exist.
	// (Standard: EX_NOHOST)
	ExitNoHost ExitCode = 68

	// ExitUnavailable indicates that a required service is unavailable.
	// (Standard: EX_UNAVAILABLE)
	ExitUnavailable ExitCode = 69

	// ExitSoftware indicates an internal software error. This is for unexpected
	// conditions and bugs ("this should never happen").
	// (Standard: EX_SOFTWARE)
	ExitSoftware ExitCode = 70

	// ExitOSErr indicates an operating system error, such as a failed system call.
	// (e.g., fork failed, couldn't create a directory).
	// (Standard: EX_OSERR)
	ExitOSErr ExitCode = 71

	// ExitOSFile indicates a critical OS file is missing or corrupt.
	// (e.g., /etc/passwd).
	// (Standard: EX_OSFILE)
	ExitOSFile ExitCode = 72

	// ExitCantCreat indicates that a user-specified output file could not be created.
	// (Standard: EX_CANTCREAT)
	ExitCantCreat ExitCode = 73

	// ExitIOErr indicates an error occurred during an I/O operation.
	// (Standard: EX_IOERR)
	ExitIOErr ExitCode = 74

	// ExitTempFail indicates a temporary failure. The user is invited to retry.
	// (Standard: EX_TEMPFAIL)
	ExitTempFail ExitCode = 75

	// ExitProtocol indicates a protocol error during network communication.
	// (Standard: EX_PROTOCOL)
	ExitProtocol ExitCode = 76

	// ExitNoPerm indicates that the user does not have sufficient permissions.
	// This is for filesystem permissions, not for authentication issues.
	// (Standard: EX_NOPERM)
	ExitNoPerm ExitCode = 77

	// ExitConfig indicates that something is wrong in a configuration file.
	// (Standard: EX_CONFIG)
	ExitConfig ExitCode = 78
)

type GuiPrep added in v0.0.4

type GuiPrep struct {
}

func Gui

func Gui() *GuiPrep

func (*GuiPrep) Start added in v0.0.4

func (g *GuiPrep) Start() error

Jump to

Keyboard shortcuts

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