argvpb

package module
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: GPL-3.0 Imports: 22 Imported by: 23

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

Functions

func BadExit added in v0.0.43

func BadExit(msg string, err error)

func Defer added in v0.0.46

func Defer(dur time.Duration, f func())

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 GetAPPNAME added in v0.0.42

func GetAPPNAME() string

deprecate ?

func GetCmd added in v0.0.46

func GetCmd() string

func GoodExit added in v0.0.43

func GoodExit(msg string)

func Init added in v0.0.46

func Init(dest any, APPNAME string, anyString string, VERSION string)

func Len added in v0.0.48

func Len() int

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 Real added in v0.0.49

func Real() []string

func RunIfTakesLonger added in v0.0.46

func RunIfTakesLonger(d time.Duration, f func()) (cancel func())

RunIfTakesLonger schedules a function `f` to run after a duration `d`. It returns a "cancel" function. If the cancel function is called before the duration `d` has passed, the scheduled function `f` will not be executed.

This is designed to be used with defer, like so:

func myFunc() {
	cancel := RunIfTakesLonger(time.Second, func() {
		fmt.Println("myFunc took more than a second!")
	})
	defer cancel()

	// ... rest of the function
}

func Version added in v0.0.46

func Version() string

Types

type App added in v0.0.41

type App struct {
	APPNAME   string `protobuf:"bytes,1,opt,name=APPNAME,proto3" json:"APPNAME,omitempty"`
	VERSION   string `protobuf:"bytes,2,opt,name=VERSION,proto3" json:"VERSION,omitempty"`
	BUILDTIME string `protobuf:"bytes,3,opt,name=BUILDTIME,proto3" json:"BUILDTIME,omitempty"`
	// contains filtered or unexported fields
}

func (*App) Descriptor deprecated added in v0.0.41

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

Deprecated: Use App.ProtoReflect.Descriptor instead.

func (*App) GetAPPNAME added in v0.0.41

func (x *App) GetAPPNAME() string

func (*App) GetBUILDTIME added in v0.0.41

func (x *App) GetBUILDTIME() string

func (*App) GetVERSION added in v0.0.41

func (x *App) GetVERSION() string

func (*App) ProtoMessage added in v0.0.41

func (*App) ProtoMessage()

func (*App) ProtoReflect added in v0.0.41

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

func (*App) Reset added in v0.0.41

func (x *App) Reset()

func (*App) String added in v0.0.41

func (x *App) String() string

type AppScanner added in v0.0.41

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

func (*AppScanner) Next added in v0.0.41

func (it *AppScanner) Next() *App

Next() returns the next thing in the array

func (*AppScanner) Scan added in v0.0.41

func (it *AppScanner) Scan() bool

type ArgTree added in v0.0.46

type ArgTree struct {
	Structs      []*StructEntry `protobuf:"bytes,1,rep,name=Structs,proto3" json:"Structs,omitempty"`           // a tree of the argv structs in argv.go
	MainArgvName string         `protobuf:"bytes,2,opt,name=mainArgvName,proto3" json:"mainArgvName,omitempty"` // name to use in main.go
	// contains filtered or unexported fields
}

func (*ArgTree) Descriptor deprecated added in v0.0.46

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

Deprecated: Use ArgTree.ProtoReflect.Descriptor instead.

func (*ArgTree) GetMainArgvName added in v0.0.46

func (x *ArgTree) GetMainArgvName() string

func (*ArgTree) GetStructs added in v0.0.46

func (x *ArgTree) GetStructs() []*StructEntry

func (*ArgTree) ProtoMessage added in v0.0.46

func (*ArgTree) ProtoMessage()

func (*ArgTree) ProtoReflect added in v0.0.46

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

func (*ArgTree) Reset added in v0.0.46

func (x *ArgTree) Reset()

func (*ArgTree) String added in v0.0.46

func (x *ArgTree) String() string

type ArgTreeScanner added in v0.0.46

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

func (*ArgTreeScanner) Next added in v0.0.46

func (it *ArgTreeScanner) Next() *ArgTree

Next() returns the next thing in the array

func (*ArgTreeScanner) Scan added in v0.0.46

func (it *ArgTreeScanner) Scan() bool

type ArgsBash added in v0.0.3

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

this is sill in development figure out how to trigger this

type Argv added in v0.0.39

type Argv struct {
	Ctime        *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=ctime,proto3" json:"ctime,omitempty"`               // set at the start of argv.Init()
	Duration     *durationpb.Duration   `protobuf:"bytes,2,opt,name=duration,proto3" json:"duration,omitempty"`         // could mean lots of things
	ArgvDuration *durationpb.Duration   `protobuf:"bytes,3,opt,name=argvDuration,proto3" json:"argvDuration,omitempty"` // how long autocomplete & match took
	AppInfo      *App                   `protobuf:"bytes,4,opt,name=appInfo,proto3" json:"appInfo,omitempty"`
	Args         []string               `protobuf:"bytes,5,rep,name=args,proto3" json:"args,omitempty"`               // a copy of os.Args
	Real         []string               `protobuf:"bytes,6,rep,name=real,proto3" json:"real,omitempty"`               // what will really be sent to the application
	Subcmd       string                 `protobuf:"bytes,7,opt,name=subcmd,proto3" json:"subcmd,omitempty"`           // the subcommand being processed. For "git pull <tab>", cmd would be "pull"
	Partial      string                 `protobuf:"bytes,8,opt,name=partial,proto3" json:"partial,omitempty"`         // if the user has only partially inputed something
	Fast         int32                  `protobuf:"varint,9,opt,name=fast,proto3" json:"fast,omitempty"`              // is autocomplete running quickly?
	Stdout       string                 `protobuf:"bytes,10,opt,name=stdout,proto3" json:"stdout,omitempty"`          // all output is loaded here before being sent to the shell
	Stderr       string                 `protobuf:"bytes,11,opt,name=stderr,proto3" json:"stderr,omitempty"`          // all output is loaded here before being sent to the shell
	Stddbg       string                 `protobuf:"bytes,12,opt,name=stddbg,proto3" json:"stddbg,omitempty"`          // all output is loaded here before being sent to the shell
	OutCounter   int32                  `protobuf:"varint,13,opt,name=outCounter,proto3" json:"outCounter,omitempty"` // counter to track if the help text has been sent to Stderr
	ErrCounter   int32                  `protobuf:"varint,14,opt,name=errCounter,proto3" json:"errCounter,omitempty"` // counter to track if the help text has been sent to Stderr
	Uuid         string                 `protobuf:"bytes,15,opt,name=uuid,proto3" json:"uuid,omitempty"`              // all output is loaded here before being sent to the shell
	// contains filtered or unexported fields
}
var PB *Argv

try a global here to see how that turns out

func Autocomplete added in v0.0.39

func Autocomplete() *Argv

This function behaves oddly. It works in several different ways. It can:

  • Initialize a protobuf and returns it to the application
  • Help a user generate shell completion support & os.Exit
  • figures out what to print to Stdout & Stderr and then does os.Exit()

func (*Argv) Descriptor deprecated added in v0.0.39

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

Deprecated: Use Argv.ProtoReflect.Descriptor instead.

func (*Argv) FormatJSON added in v0.0.39

func (v *Argv) FormatJSON() string

human readable JSON

func (*Argv) FormatTEXT added in v0.0.39

func (v *Argv) 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 (*Argv) GetAppInfo added in v0.0.42

func (x *Argv) GetAppInfo() *App

func (*Argv) GetArgs added in v0.0.44

func (x *Argv) GetArgs() []string

func (*Argv) GetArgvDuration added in v0.0.49

func (x *Argv) GetArgvDuration() *durationpb.Duration

func (*Argv) GetCmd added in v0.0.39

func (pb *Argv) GetCmd() string

todo: this is wrong

func (*Argv) GetCtime added in v0.0.39

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

func (*Argv) GetDuration added in v0.0.39

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

func (*Argv) GetErrCounter added in v0.0.49

func (x *Argv) GetErrCounter() int32

func (*Argv) GetFast added in v0.0.39

func (x *Argv) GetFast() int32

func (*Argv) GetOutCounter added in v0.0.49

func (x *Argv) GetOutCounter() int32

func (*Argv) GetPartial added in v0.0.39

func (x *Argv) GetPartial() string

func (*Argv) GetReal added in v0.0.39

func (x *Argv) GetReal() []string

func (*Argv) GetStddbg added in v0.0.48

func (x *Argv) GetStddbg() string

func (*Argv) GetStderr added in v0.0.44

func (x *Argv) GetStderr() string

func (*Argv) GetStdout added in v0.0.44

func (x *Argv) GetStdout() string

func (*Argv) GetSubcmd added in v0.0.44

func (x *Argv) GetSubcmd() string

func (*Argv) GetUuid added in v0.0.46

func (x *Argv) GetUuid() string

func (*Argv) Gui added in v0.0.41

func (pb *Argv) Gui() bool

maybe this is a good idea, maybe not

func (*Argv) IsMatch added in v0.0.43

func (pb *Argv) IsMatch(match string) bool

func (*Argv) Marshal added in v0.0.39

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

marshal to wire. This is called winning.

func (*Argv) MarshalJSON added in v0.0.39

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

marshal json

func (*Argv) ProtoMessage added in v0.0.39

func (*Argv) ProtoMessage()

func (*Argv) ProtoReflect added in v0.0.39

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

func (*Argv) Reset added in v0.0.39

func (x *Argv) Reset()

func (*Argv) String added in v0.0.39

func (x *Argv) String() string

func (*Argv) Unmarshal added in v0.0.39

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

unmarshal from wire. You have won.

func (*Argv) UnmarshalJSON added in v0.0.39

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

unmarshal json

func (*Argv) UnmarshalTEXT added in v0.0.39

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

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

func (*Argv) Version added in v0.0.39

func (pb *Argv) Version() string

type ArgvScanner added in v0.0.39

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

func (*ArgvScanner) Next added in v0.0.39

func (it *ArgvScanner) Next() *Argv

Next() returns the next thing in the array

func (*ArgvScanner) Scan added in v0.0.39

func (it *ArgvScanner) Scan() bool

type Argvs added in v0.0.39

type Argvs struct {
	Uuid     string  `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`       // `autogenpb:uuid:1e6e765c-0c77-4c81-a622-0d819bfcce9a`
	Version  string  `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v0.0.6`
	Argvs    []*Argv `protobuf:"bytes,3,rep,name=argvs,proto3" json:"argvs,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 NewArgvs added in v0.0.39

func NewArgvs() *Argvs

func (*Argvs) All added in v0.0.39

func (x *Argvs) All() *ArgvScanner

func (*Argvs) Append added in v0.0.39

func (x *Argvs) Append(y *Argv)

a Append() shortcut (that does Clone() with a mutex) notsure if it really works doesn't allow nil

func (*Argvs) Clone added in v0.0.39

func (x *Argvs) Clone(y *Argv) *Argv

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

func (*Argvs) Delete added in v0.0.39

func (x *Argvs) Delete(y *Argv) bool

func (*Argvs) Descriptor deprecated added in v0.0.39

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

Deprecated: Use Argvs.ProtoReflect.Descriptor instead.

func (*Argvs) FormatJSON added in v0.0.39

func (v *Argvs) FormatJSON() string

human readable JSON

func (*Argvs) FormatTEXT added in v0.0.39

func (v *Argvs) 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 (*Argvs) GetArgvs added in v0.0.39

func (x *Argvs) GetArgvs() []*Argv

func (*Argvs) GetFilename added in v0.0.39

func (x *Argvs) GetFilename() string

func (*Argvs) GetUuid added in v0.0.39

func (x *Argvs) GetUuid() string

func (*Argvs) GetVersion added in v0.0.39

func (x *Argvs) GetVersion() string

func (*Argvs) IterAll added in v0.0.39

func (x *Argvs) IterAll() iter.Seq[*Argv]

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

func (*Argvs) Len added in v0.0.39

func (x *Argvs) Len() int

func (*Argvs) Load added in v0.0.39

func (pb *Argvs) Load() error

func (*Argvs) Marshal added in v0.0.39

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

marshal to wire. This is called winning.

func (*Argvs) MarshalJSON added in v0.0.39

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

marshal json

func (*Argvs) ProtoMessage added in v0.0.39

func (*Argvs) ProtoMessage()

func (*Argvs) ProtoReflect added in v0.0.39

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

func (*Argvs) Reset added in v0.0.39

func (x *Argvs) Reset()

func (*Argvs) Save added in v0.0.39

func (pb *Argvs) Save() error

func (*Argvs) String added in v0.0.39

func (x *Argvs) String() string

func (*Argvs) Unmarshal added in v0.0.39

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

unmarshal from wire. You have won.

func (*Argvs) UnmarshalJSON added in v0.0.39

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

unmarshal json

func (*Argvs) UnmarshalTEXT added in v0.0.39

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

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

type ArgvsScanner added in v0.0.39

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

func (*ArgvsScanner) Next added in v0.0.39

func (it *ArgvsScanner) Next() *Argvs

Next() returns the next thing in the array

func (*ArgvsScanner) Scan added in v0.0.39

func (it *ArgvsScanner) Scan() bool

type AutoType added in v0.0.46

type AutoType struct {
	Err error // store any errors from argv

	Argv func([]string) // the function for shell autocomplete
	// contains filtered or unexported fields
}

this is a work in progress

type ExitCode added in v0.0.38

type ExitCode int
const (
	ExitSuccess     ExitCode = 0      // the program completed its task without errors.
	ExitFailure     ExitCode = 1      // generic, catch-all code for "something went wrong."
	ExitUsage       ExitCode = 64     // EX_USAGE:       user provided invalid command-line arguments or flags.
	ExitDataErr     ExitCode = 65     // EX_DATAERR:     input data was incorrect or malformed.
	ExitNoInput     ExitCode = 66     // EX_NOINPUT:     an input file was not found or could not be read.
	ExitNoUser      ExitCode = 67     // EX_NOUSER:      a specified user did not exist.
	ExitNoHost      ExitCode = 68     // EX_NOHOST:      a specified host did not exist.
	ExitUnavailable ExitCode = 69     // EX_UNAVAILABLE: a required service is unavailable.
	ExitSoftware    ExitCode = 70     // EX_SOFTWARE:    internal software error. bugs ("this should never happen")
	ExitOSErr       ExitCode = 71     // EX_OSERR:       an operating system error, such as a failed system call.
	ExitOSFile      ExitCode = 72     // EX_OSFILE:      a critical OS file is missing or corrupt. (e.g., /etc/passwd)
	ExitCantCreate  ExitCode = 73     // EX_CANTCREATE:  a user-specified output file could not be created.
	ExitIOErr       ExitCode = 74     // EX_IOERR:       an error occurred during an I/O operation.
	ExitTempFail    ExitCode = 75     // EX_TEMPFAIL:    temporary failure. The user is invited to retry.
	ExitProtocol    ExitCode = 76     // EX_PROTOCOL:    protocol error during network communication.
	ExitNoPerm      ExitCode = 77     // EX_NOPERM:      the user does not have sufficient filesystem permissions.
	ExitConfig      ExitCode = 78     // EX_CONFIG:      something is wrong in a configuration file.
	Exit126         ExitCode = 126    // Reserved for shell (command not executable)
	Exit127         ExitCode = 127    // Reserved for shell (command not found)
	Exit128         ExitCode = 128    // Reserved for shell (termination by a signal)
	ExitPB          ExitCode = 252525 // NEW FOR ARGV:   return a protobuf on exit. todo: need someone to make an RFC for this
	Exit109         ExitCode = 109    // for testing argv. 109 = 252525 % 256
)

func (ExitCode) String added in v0.0.50

func (x ExitCode) String() string

todo: finish this struct

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

type StringWriter added in v0.0.46

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

StringWriter is a custom type that implements the io.Writer interface for a string variable. It holds a pointer to the string it will write to.

var Stddbg *StringWriter // argv writes it's internal debugging output here
var Stderr *StringWriter // bash dumps this as "help" about application options
var Stdout *StringWriter // bash uses this to match strings

func NewStringWriter added in v0.0.46

func NewStringWriter(s *string) *StringWriter

NewStringWriter creates a new StringWriter that writes to the provided string pointer.

func (*StringWriter) Write added in v0.0.46

func (sw *StringWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. It appends the byte slice `p` to the string pointed to by the StringWriter.

type StructEntry added in v0.0.46

type StructEntry struct {
	StructName string `protobuf:"bytes,1,opt,name=structName,proto3" json:"structName,omitempty"` // 'Force', 'Verbose', 'SortCmd'
	StructType string `protobuf:"bytes,2,opt,name=structType,proto3" json:"structType,omitempty"` // 'string', 'int', '[]string', '*FindCmd'
	DefaultVal string `protobuf:"bytes,3,opt,name=defaultVal,proto3" json:"defaultVal,omitempty"` // "true"
	HelpText   string `protobuf:"bytes,4,opt,name=helpText,proto3" json:"helpText,omitempty"`     // "This will help you"
	MatchText  string `protobuf:"bytes,5,opt,name=matchText,proto3" json:"matchText,omitempty"`   //  "--help-me
	// contains filtered or unexported fields
}

func (*StructEntry) Descriptor deprecated added in v0.0.46

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

Deprecated: Use StructEntry.ProtoReflect.Descriptor instead.

func (*StructEntry) GetDefaultVal added in v0.0.46

func (x *StructEntry) GetDefaultVal() string

func (*StructEntry) GetHelpText added in v0.0.46

func (x *StructEntry) GetHelpText() string

func (*StructEntry) GetMatchText added in v0.0.46

func (x *StructEntry) GetMatchText() string

func (*StructEntry) GetStructName added in v0.0.46

func (x *StructEntry) GetStructName() string

func (*StructEntry) GetStructType added in v0.0.46

func (x *StructEntry) GetStructType() string

func (*StructEntry) ProtoMessage added in v0.0.46

func (*StructEntry) ProtoMessage()

func (*StructEntry) ProtoReflect added in v0.0.46

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

func (*StructEntry) Reset added in v0.0.46

func (x *StructEntry) Reset()

func (*StructEntry) String added in v0.0.46

func (x *StructEntry) String() string

type StructEntryScanner added in v0.0.46

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

func (*StructEntryScanner) Next added in v0.0.46

func (it *StructEntryScanner) Next() *StructEntry

Next() returns the next thing in the array

func (*StructEntryScanner) Scan added in v0.0.46

func (it *StructEntryScanner) Scan() bool

Jump to

Keyboard shortcuts

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