CnsPanel

package
v0.2.38 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package CnsPanel provides a structure and functions for handling console command flags.

Package CnsPanel provides a structure and functions for handling console command flags.

Package CnsPanel provides a structure and functions for handling console command flags.

Package CnsPanel provides a structure and functions for handling console command flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments added in v0.2.33

type Arguments map[string]any

Arguments is a map of string keys to any values representing the arguments passed to a command.

Key: The name of the argument. Value: The value of the argument.

type CommandCallbackFunc added in v0.2.33

type CommandCallbackFunc func(args map[string]any) error

CommandCallbackFunc is a function type that represents a callback function for a console command.

Parameters:

  • args: A map of string keys to any values representing the arguments passed to the command.

Returns:

  • error: An error if the command fails.

type CommandInfo added in v0.2.33

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

CommandInfo represents a console command.

func NewCommandInfo added in v0.2.33

func NewCommandInfo(commandName string, callback CommandCallbackFunc) *CommandInfo

NewCommandInfo creates a new CommandInfo with the provided name and callback function.

Parameters:

  • commandName: The name of the command.
  • callback: The function to call when the command is used.

Returns:

  • *CommandInfo: A pointer to the new CommandInfo.

func (*CommandInfo) AddFlags added in v0.2.34

func (ci *CommandInfo) AddFlags(flags ...*FlagInfo)

AddFlags is a method of CommandInfo that adds a new flag to a CommandInfo.

Nil flags are ignored.

Parameters:

  • flags: The flags to add.

func (*CommandInfo) FString added in v0.2.33

func (cci *CommandInfo) FString(indentLevel int) []string

FString generates a formatted string representation of a CommandInfo. It includes the command name, description, usage information for each flag, and the list of flags and their details.

Parameters:

  • indentLevel: The level of indentation to use. Sign is ignored.

Returns:

  • []string: A slice of strings representing the CommandInfo.

func (*CommandInfo) SetDescription added in v0.2.33

func (ci *CommandInfo) SetDescription(description *Description)

SetDescription sets the description for a CommandInfo. It splits each line of the description by newline characters.

Parameters:

  • description: The description to set.

type ConsolePanel

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

ConsolePanel represents a command line console.

func NewConsolePanel added in v0.2.34

func NewConsolePanel(execName string) *ConsolePanel

NewConsolePanel creates a new ConsolePanel with the provided executable name.

Parameters:

  • execName: The name of the executable.

Returns:

  • *ConsolePanel: A pointer to the created ConsolePanel.

func (*ConsolePanel) AddCommands added in v0.2.34

func (cp *ConsolePanel) AddCommands(commands ...*CommandInfo)

AddCommands adds the provided commands to the ConsolePanel. Nil commands are ignored and the existing commands are replaced.

Parameters:

  • commands: The commands to add to the ConsolePanel.

func (*ConsolePanel) FString

func (cns *ConsolePanel) FString(indentLevel int) []string

FString generates a formatted string representation of a ConsolePanel. It includes the usage information, and the list of commands and their details.

Parameters:

  • indentLevel: The level of indentation to use for the ConsolePanel.

Returns:

  • []string: A slice of strings representing the ConsolePanel.

func (*ConsolePanel) ParseArguments added in v0.2.33

func (cns *ConsolePanel) ParseArguments(args []string) (*ParsedCommand, error)

ParseArguments parses the provided command line arguments and returns a ParsedCommand ready to be executed.

Errors:

  • *ers.ErrInvalidParameter: No arguments provided.
  • *ErrCommandNotFound: Command not found.
  • *ErrParsingFlags: Error parsing flags.

Parameters:

  • args: The command line arguments to parse. Without the executable name.

Returns:

  • *ParsedCommand: A pointer to the parsed command.
  • error: An error, if any.

func (*ConsolePanel) SetDescription added in v0.2.34

func (b *ConsolePanel) SetDescription(description *Description)

AppendParagraph is a method of ConsoleBuilder that appends a paragraph to the description of a ConsoleBuilder.

Parameters:

  • contents: The contents of the paragraph to append.

type Description added in v0.2.34

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

Description represents a description for a flag, command, or any other object that requires a description.

func NewDescription added in v0.2.34

func NewDescription() *Description

NewDescription creates a new Description.

Returns:

  • *Description: A pointer to the new Description.

func (*Description) AddNewline added in v0.2.34

func (d *Description) AddNewline()

AddNewline adds a newline to the description.

func (*Description) Append added in v0.2.34

func (d *Description) Append(elem ...string)

Append appends multiple elements to the description in a single line.

Parameters:

  • elem: The elements of a single line.

func (*Description) AppendFullLine added in v0.2.34

func (d *Description) AppendFullLine(line string)

AppendFullLine appends a full line to the description.

Parameters:

  • line: The line to append.

func (*Description) FString added in v0.2.34

func (d *Description) FString(indentLevel int) []string

FString generates a formatted string representation of a Description.

Parameters:

  • indentLevel: The level of indentation to use. Sign is ignored.

Returns:

  • []string: A slice of strings representing the Description.

func (*Description) String added in v0.2.34

func (d *Description) String() string

String returns the description as a string.

Returns:

  • string: The description as a string.

type ErrCommandNotFound added in v0.2.33

type ErrCommandNotFound struct {
	// The command that was not found.
	Command string
}

ErrCommandNotFound represents an error where a command is not found.

func NewErrCommandNotFound added in v0.2.33

func NewErrCommandNotFound(command string) *ErrCommandNotFound

NewErrCommandNotFound creates a new ErrCommandNotFound with the provided command.

Parameters:

  • command: The command that was not found.

Returns:

  • *ErrCommandNotFound: A pointer to the new ErrCommandNotFound.

func (*ErrCommandNotFound) Error added in v0.2.33

func (e *ErrCommandNotFound) Error() string

Error returns the error message for an ErrCommandNotFound.

Returns:

  • string: The error message.

type ErrFewArguments added in v0.2.33

type ErrFewArguments struct{}

ErrFewArguments represents an error where not enough arguments are provided.

func NewErrFewArguments added in v0.2.33

func NewErrFewArguments() *ErrFewArguments

NewErrFewArguments creates a new ErrFewArguments.

Returns:

  • *ErrFewArguments: A pointer to the new ErrFewArguments.

func (*ErrFewArguments) Error added in v0.2.33

func (e *ErrFewArguments) Error() string

Error returns the error message for an ErrFewArguments.

Returns:

  • string: The error message.

type ErrParsingFlags added in v0.2.33

type ErrParsingFlags struct {
	// Name is the flag that could not be parsed.
	Name string

	// Reason is the reason the flag could not be parsed.
	Reason error
}

ErrParsingFlags represents an error where flags could not be parsed.

func NewErrParsingFlags added in v0.2.33

func NewErrParsingFlags(name string, reason error) *ErrParsingFlags

NewErrParsingFlags creates a new ErrParsingFlags with the provided name and reason.

Parameters:

  • name: The flag that could not be parsed.
  • reason: The reason the flag could not be parsed.

Returns:

  • *ErrParsingFlags: A pointer to the new ErrParsingFlags.

func (*ErrParsingFlags) Error added in v0.2.33

func (e *ErrParsingFlags) Error() string

Error returns the error message for an ErrParsingFlags.

Returns:

  • string: The error message.

func (*ErrParsingFlags) Unwrap added in v0.2.33

func (e *ErrParsingFlags) Unwrap() error

Unwrap returns the reason the flags could not be parsed.

Returns:

  • error: The reason the flags could not be parsed.

type ErrUnknownFlag added in v0.2.33

type ErrUnknownFlag struct{}

ErrUnknownFlag represents an error where an unknown flag is provided.

func NewErrUnknownFlag added in v0.2.33

func NewErrUnknownFlag() *ErrUnknownFlag

NewErrUnknownFlag creates a new ErrUnknownFlag.

Returns:

  • *ErrUnknownFlag: A pointer to the new ErrUnknownFlag.

func (*ErrUnknownFlag) Error added in v0.2.33

func (e *ErrUnknownFlag) Error() string

Error returns the error message for an ErrUnknownFlag.

Returns:

  • string: The error message.

type FlagCallbackFunc added in v0.2.33

type FlagCallbackFunc func(...string) (any, error)

FlagCallbackFunc is a function type that represents a callback function for a console command flag.

Parameters:

  • args: A slice of strings representing the arguments passed to the flag.

Returns:

  • any: Any value representing the result of the flag callback.
  • error: An error if the flag fails.

type FlagInfo added in v0.2.33

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

FlagInfo represents a flag for a console command.

func NewFlagInfo added in v0.2.33

func NewFlagInfo(name string, isRequired bool, callback FlagCallbackFunc, args ...string) *FlagInfo

NewFlagInfo creates a new FlagInfo with the given name and arguments.

Parameters:

  • name: The name of the flag.
  • isRequired: A boolean indicating whether the flag is required.
  • args: A slice of strings representing the arguments accepted by the flag.

Returns:

  • *FlagInfo: A pointer to the new FlagInfo.

func (*FlagInfo) Equals added in v0.2.33

func (fi *FlagInfo) Equals(other *FlagInfo) bool

Equals compares two FlagInfo objects to determine if they are equal. Two FlagInfo objects are considered equal if they have the same name and arguments. The latter of which can be in any order.

Parameters:

  • other: The other FlagInfo to compare.

Returns:

  • bool: A boolean indicating whether the two FlagInfo objects are equal.

func (*FlagInfo) FString added in v0.2.33

func (cfi *FlagInfo) FString(indentLevel int) []string

FString generates a formatted string representation of a FlagInfo, including the flag name, arguments, description, and whether it is required.

Parameters:

  • indentLevel: The level of indentation to use. Sign is ignored.

Returns:

  • []string: A slice of strings representing the FlagInfo.

func (*FlagInfo) SetDescription added in v0.2.33

func (cfi *FlagInfo) SetDescription(description *Description)

SetDescription sets the description of a FlagInfo.

Parameters:

  • description: The description of the FlagInfo.

type ParsedCommand added in v0.2.33

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

ParsedCommand represents a parsed console command.

func (*ParsedCommand) Command added in v0.2.33

func (pc *ParsedCommand) Command() string

Command returns the name of the command.

Returns:

  • string: The name of the command.

func (*ParsedCommand) Run added in v0.2.33

func (pc *ParsedCommand) Run() error

Run executes the callback function for the parsed command.

Returns:

  • error: An error, if any.

Jump to

Keyboard shortcuts

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