cml

package module
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: MIT Imports: 9 Imported by: 0

README

LyneCmL

A personal command line handler

Complex is still Wip while Simple is only for straight forward programs and applets.

Because it is a personal command line handler, it is not recommended to use it for production; nor to rely on it for any work. ;-)

Maybe with time, it will be more robust and reliable at such point that it could be used for production.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultExitSequence

func DefaultExitSequence(err error)

DefaultExitSequence is the default exit sequence.

In the default exit sequence, the error is printed if it is not nil, and "Success" is printed if it is nil. The user is then prompted to press ENTER to exit.

Parameters:

  • err: The error that may have occurred.

Types

type Argument

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

Argument is an argument.

var (
	// NoArguments is the default argument.
	NoArguments *Argument
)

func ExactArgs

func ExactArgs(arg string) *Argument

ExactArgs returns an argument with the given name.

Parameters:

  • arg: The name of the argument.

Returns:

  • *Argument: The argument.

type Command

type Command struct {
	// Name is the name of the command.
	Name string

	// Brief is the brief description of the command.
	Brief string

	// Args is the arguments of the command.
	Args *Argument

	// RunFn is the function that runs the command.
	RunFn RunFn
}

Command is a command.

func (*Command) Fix

func (c *Command) Fix() error

Fix implements the errors.Fixer interface.

type Program

type Program struct {
	// Name is the name of the program
	Name string

	// Version is the version of the program
	Version string

	// Brief is the brief description of the program
	Brief string
	// contains filtered or unexported fields
}

Program is a collection of commands

func (*Program) AddCommand

func (p *Program) AddCommand(cmd *Command)

AddCommand adds a command if it is not nil.

Parameters:

  • cmd: The command to add.

Does nothing if the receiver is nil.

func (*Program) AddCommands

func (p *Program) AddCommands(cmds ...*Command)

AddCommands is a more convenient way to add multiple commands.

Parameters:

  • cmds: The commands to add.

Does nothing if the receiver is nil.

func (Program) Command

func (p Program) Command() iter.Seq2[string, *Command]

Command returns a sequence of commands.

Parameters:

  • name: The name of the command.

Returns:

  • iter.Seq2[string, *Command]: A sequence of commands. Never returns nil.

func (*Program) Fix

func (p *Program) Fix() error

Fix implements the errors.Fixer interface.

func (Program) Print

func (p Program) Print(args ...any) error

Print prints the given arguments. A newline is always printed at the end and a space is added between arguments.

No arguments will print a newline.

Parameters:

  • args: The arguments to print.

Returns:

  • error: Any error that may have occurred.

func (Program) Printf

func (p Program) Printf(format string, args ...any) error

Printf prints the given format and arguments. However, a newline is always printed at the end.

Parameters:

  • format: The format to print.
  • args: The arguments to print.

Returns:

  • error: Any error that may have occurred.

func (*Program) Run

func (p *Program) Run(args []string) error

Run runs the program.

Parameters:

  • args: The command line arguments. This is expected to be os.Args.

Returns:

  • error: Any error that may have occurred.

func (*Program) TabWriter

func (p *Program) TabWriter(min_width, tab_width, padding int) TabWriter

TabWriter returns a TabWriter. For the arguments, see tabwriter.NewWriter.

Parameters:

  • min_width: The minimum width.
  • tab_width: The tab width.
  • padding: The padding.

Returns:

  • TabWriter: The TabWriter.

func (Program) Write

func (p Program) Write(b []byte) (int, error)

Write implements the io.Writer interface.

type RunFn

type RunFn func(p *Program, args []string) error

RunFn is a function that runs the command.

Parameters:

  • p: The program. Assumed to not be nil.
  • args: The command line arguments.

Returns:

  • error: Any error that may have occurred.

type TabWriter

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

TabWriter is a TabWriter.

func (TabWriter) Flush

func (tw TabWriter) Flush() error

Flush flushes the TabWriter.

Returns:

  • error: Any error that may have occurred.

func (TabWriter) PrintRow

func (tw TabWriter) PrintRow(columns ...string) error

PrintRow prints a row of data.

Parameters:

  • columns: The columns to print.

Returns:

  • error: Any error that may have occurred.

Jump to

Keyboard shortcuts

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