replyme

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 35 Imported by: 0

README

Replyme Logo

Replyme

A tool for creating REPL sessions in Golang.

[English] [Русский]

Go Reference Go Report Card GitHub Release GitHub Actions Workflow Status

[!CAUTION] This project may contain errors and flaws, as its development has just begun. Read more about this in the Bugs and Roadmap section

Usage

To use Replyme, first install it in your project using the command:

go get github.com/danyasatsuk/replyme

After that, start creating your first REPL!

package main

import "github.com/danyasatsuk/replyme"

func main() {
    app := &replyme.App{
        Name:  "hello",
        Usage: "Hello World",
        Commands: []*replyme.Command{
            {
                Name:  "hello",
                Usage: "Print Hello World",
                Action: func(ctx *replyme.Context) error {
                    ctx.Print("Hello, World!")
                    return nil
                },
            },
        },
    }
    
    err := replyme.Run(app)
    if err != nil {
        panic(err)
    }
}

You can find out more about how it works in the examples directory.

Bugs and Roadmap

Be careful, at the moment this project is still in the very initial development stage, and there may be a lot of flaws in it. At the moment, future edits have been made to the file. TODO.md (Russian). If you find a mistake, please describe it by creating a new Issue, I will be very grateful to you!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorArgumentNotFound = errors.New("argument not found for command")
View Source
var ErrorCommandEmpty = errors.New("command empty")
View Source
var ErrorCommandPanic = errors.New("cmdpanic")
View Source
var ErrorCommandUnclosedQuotes = errors.New("unclosed quotes")
View Source
var ErrorIncompleteEscapeSequence = errors.New("incomplete escape sequence")
View Source
var ErrorSubcommandUnknown = errors.New("unknown subcommand")
View Source
var ErrorUnknownCommand = errors.New("unknown command")
View Source
var ErrorUnknownFlagType = errors.New("unknown flag type")
View Source
var HelpCommandTemplate = `` /* 608-byte string literal not displayed */

Functions

func L

func L(id string) string

func Run

func Run(app *App) error

Run starts the REPL.

func RunCLI added in v0.1.0

func RunCLI(app *App) error

Types

type ASTArgument

type ASTArgument struct {
	// Argument name
	Name string
	// Argument value
	Value string
}

ASTArgument - is a structure for storing arguments inside the AST.

type ASTFlag

type ASTFlag struct {
	// Flag type
	Type FlagType
	// Flag value
	Value string
}

ASTFlag - is a structure for storing flags inside the AST.

type ASTNode

type ASTNode struct {
	Command      string
	FullCommand  string
	CommandTree  []string
	Subcommands  []string
	Arguments    []ASTArgument
	Flags        map[string]map[string][]ASTFlag
	Args         []string
	ColorCommand string
}

ASTNode - is a structure that defines the storage of a command after its successful parsing.

type App

type App struct {
	// The name of your application
	Name string
	// Description of the application, why it is needed
	Usage string
	// The authors of the application
	Authors []string
	// Your copyright in the form of "YEAR-YEAR author"
	Copyright string
	// The license under which you distribute the code
	License string

	// A list of all your commands
	Commands Commands

	// Allows you to enable Debug mode (with it, all Debug messages are output to the console)
	Debug bool
	// Allows you to disable the color output
	NoColor bool
	// Application parameters. For more information, see AppParams.
	Params AppParams
}

App - the structure of the application.

type AppParams

type AppParams struct {
	// Allows you to turn on the cursor blinking inside the input. It's not working yet, added to the Roadmap.
	//nolint:godox
	//TODO(unimportant): Add cursor blinking
	EnableInputBlinking bool
}

AppParams - the structure of the application parameters.

type Argument

type Argument struct {
	Name  string
	Usage string
	// contains filtered or unexported fields
}

Argument is a structure that describes the arguments for your command.

func (*Argument) GetValue

func (arg *Argument) GetValue() string

GetValue - method for getting the value of an argument.

type Command

type Command struct {
	// Command name
	Name string
	// What is this command for?
	Usage string
	// Allows you to specify abbreviations for the command
	Aliases []string
	// The subcommands of your main command
	Subcommands Commands
	// Flags for executing your command
	Flags Flags
	// Arguments for executing your command
	Arguments []*Argument
	// The function that is executed before executing the main function Action
	Before func(ctx *Context) (bool, error)
	// The main function of the command
	Action func(ctx *Context) error
	// A function that runs after the main Action function has successfully completed its action
	OnEnd func(ctx *Context) error
}

Command - the structure for creating your command.

type Commands

type Commands []*Command

Commands is an abbreviation for the type `[]*replyme.Command`.

type Context

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

Context - the structure that is passed when executing the functions of the command.

func (*Context) Command

func (c *Context) Command() string

Command is a method for getting the command string.

func (*Context) Confirm

func (c *Context) Confirm(p *TUIConfirmParams) (bool, error)

Confirm is a method that triggers TUI to receive confirmation from the user.

func (*Context) Ctx

func (c *Context) Ctx() context.Context

Ctx is a method for getting the context.Context.

func (*Context) Delete

func (c *Context) Delete(key string)

Delete is a method for deleting a value from the memory.

func (*Context) Done

func (c *Context) Done() <-chan struct{}

Done is a method for getting the done channel.

func (*Context) Elapsed

func (c *Context) Elapsed() time.Duration

Elapsed is a method for getting the elapsed time of the command.

func (*Context) Error

func (c *Context) Error(data ...interface{})

Error is a method for printing an error message.

func (*Context) Errorf

func (c *Context) Errorf(format string, data ...interface{})

Errorf is a method for printing a formatted error message.

func (*Context) Exec

func (c *Context) Exec(cmd string, args ...string) (string, string, error)

Exec is a method for executing a shell command.

func (*Context) ExecLive

func (c *Context) ExecLive(cmd string, args ...string) error

ExecLive is a method for executing a shell command in a live environment.

func (*Context) ExecSilent

func (c *Context) ExecSilent(cmd string, args ...string) error

ExecSilent is a method for executing a shell command silently.

func (*Context) Get

func (c *Context) Get(key string) interface{}

Get is a method for getting a value from the memory.

func (*Context) GetCommandNameTree

func (c *Context) GetCommandNameTree() []string

GetCommandNameTree is a method for getting a command tree.

func (*Context) GetFlagBool

func (c *Context) GetFlagBool(name string) bool

GetFlagBool is a method for getting a flag bool value.

func (*Context) GetFlagInt

func (c *Context) GetFlagInt(name string, defaultValue int) int

GetFlagInt is a method for getting a flag int value.

func (*Context) GetFlagIntArray

func (c *Context) GetFlagIntArray(name string) []int

GetFlagIntArray is a method for getting a flag int array value.

func (*Context) GetFlagString

func (c *Context) GetFlagString(name string, defaultValue string) string

GetFlagString is a method for getting a flag string value.

func (*Context) GetFlagStringArray

func (c *Context) GetFlagStringArray(name string) []string

GetFlagStringArray is a method for getting a flag string array value.

func (*Context) GetName

func (c *Context) GetName() string

GetName - returns the name of the command.

func (*Context) InputFile

func (c *Context) InputFile(p *TUIInputFileParams) (TUIInputFileResult, error)

InputFile is a method that triggers TUI to receive file from the user.

func (*Context) InputInt

func (c *Context) InputInt(p *TUIInputIntParams) (int, error)

InputInt is a method that triggers TUI to receive integer from the user.

func (*Context) InputText

func (c *Context) InputText(p *TUIInputTextParams) (string, error)

InputText is a method that triggers TUI to receive text from the user.

func (*Context) IsCancelled

func (c *Context) IsCancelled() bool

IsCancelled is a method for checking if the context is cancelled.

func (*Context) MustGetInt

func (c *Context) MustGetInt(key string) int

MustGetInt is a method for getting a value from the memory and converting it to an int.

func (*Context) MustGetString

func (c *Context) MustGetString(key string) string

MustGetString is a method for getting a value from the memory and converting it to a string.

func (*Context) Print

func (c *Context) Print(data ...interface{})

Print is a method for printing a message.

func (*Context) PrintMarkdown

func (c *Context) PrintMarkdown(markdown string, data ...interface{})

PrintMarkdown is a method for printing a markdown message.

func (*Context) Printf

func (c *Context) Printf(format string, data ...interface{})

Printf is a method for printing a formatted message.

func (*Context) SelectOne

func (c *Context) SelectOne(p *TUISelectOneParams) (TUISelectOneResult, error)

SelectOne is a method that triggers TUI to receive one item from the list from the user.

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set is a method for setting a value in the memory.

func (*Context) StartTime

func (c *Context) StartTime() time.Time

StartTime is a method for getting the start time of the command.

func (*Context) Stderr

func (c *Context) Stderr() io.Writer

Stderr is a method for getting the stderr writer.

func (*Context) Stdout

func (c *Context) Stdout() io.Writer

Stdout is a method for getting the stdout writer.

func (*Context) Warn

func (c *Context) Warn(data ...interface{})

Warn is a method for printing a warning message.

func (*Context) Warnf

func (c *Context) Warnf(format string, data ...interface{})

Warnf is a method for printing a formatted warning message.

type Flag

type Flag interface {
	// GetName returns the name of the flag.
	GetName() string
	// GetAlias returns the alias of the flag.
	GetAlias() string
	// ValueType returns the type of the value.
	ValueType() string
	// Value returns the value of the flag.
	Value() string
	// Parse parses the flag.
	Parse(flag string) (interface{}, error)
	// ParsedValue returns the parsed value of the flag.
	ParsedValue() (interface{}, error)
	// GetUsage returns the usage of the flag.
	GetUsage() string
	// Clear clears the flag.
	Clear()
}

Flag is an interface for getting information about flags and parsing it.

type FlagType

type FlagType uint16
const (
	FlagTypeInt FlagType = iota
	FlagTypeString
	FlagTypeIntArray
	FlagTypeStringArray
	FlagTypeBool
)

type FlagValue

type FlagValue[T any] struct {
	// Flag name
	Name string
	// Flag usage
	Usage string
	// Flag alias
	Alias string
	// Flag parser
	Parser func(s string) (T, error)
	// contains filtered or unexported fields
}

FlagValue is a structure for passing information about flags to a command.

func (*FlagValue[T]) Clear added in v0.0.2

func (f *FlagValue[T]) Clear()

Clear clears the flag.

func (*FlagValue[T]) GetAlias

func (f *FlagValue[T]) GetAlias() string

GetAlias returns the alias of the flag.

func (*FlagValue[T]) GetName

func (f *FlagValue[T]) GetName() string

GetName returns the name of the flag.

func (*FlagValue[T]) GetUsage

func (f *FlagValue[T]) GetUsage() string

GetUsage returns the usage of the flag.

func (*FlagValue[T]) Parse

func (f *FlagValue[T]) Parse(flag string) (interface{}, error)

Parse parses the flag.

func (*FlagValue[T]) ParsedValue

func (f *FlagValue[T]) ParsedValue() (interface{}, error)

ParsedValue returns the parsed value of the flag.

func (*FlagValue[T]) Value

func (f *FlagValue[T]) Value() string

Value returns the value of the flag.

func (*FlagValue[T]) ValueType

func (f *FlagValue[T]) ValueType() string

ValueType returns the type of the value.

type Flags

type Flags []Flag

Flags is an abbreviation for the type `[]Flag`, which adds additional methods for convenient management.

func (Flags) GetFlagBool

func (f Flags) GetFlagBool(name string) bool

GetFlagBool returns the value of the flag with the specified name as a bool.

func (Flags) GetFlagInt

func (f Flags) GetFlagInt(name string, defaultValue int) int

GetFlagInt returns the value of the flag with the specified name as an int.

func (Flags) GetFlagIntArray

func (f Flags) GetFlagIntArray(name string) []int

GetFlagIntArray returns the value of the flag with the specified name as an array of ints.

func (Flags) GetFlagString

func (f Flags) GetFlagString(name string, defaultValue string) string

GetFlagString returns the value of the flag with the specified name as a string.

func (Flags) GetFlagStringArray

func (f Flags) GetFlagStringArray(name string) []string

GetFlagStringArray returns the value of the flag with the specified name as an array of strings.

type TUIConfirmParams

type TUIConfirmParams struct {
	Name        string
	Description string
}

type TUIInputFileParams

type TUIInputFileParams struct {
	Name        string
	Description string
	Extensions  []string
	MaxFileSize int
	DoNotOutput bool
}

type TUIInputFileResult

type TUIInputFileResult struct {
	Path string
	File []byte
}

type TUIInputIntParams

type TUIInputIntParams struct {
	Name        string
	Description string
	MinValue    int
	MaxValue    int
	Validate    func(s string) bool
}

type TUIInputTextParams

type TUIInputTextParams struct {
	Name        string
	Description string
	Placeholder string
	IsPassword  bool
	Validate    func(s string) bool
	MaxLength   int
}

type TUIRequest

type TUIRequest struct {
	ID       string
	Type     tuiType
	Payload  interface{}
	Response chan TUIResponse
}

type TUIResponse

type TUIResponse struct {
	Value interface{}
	Err   error
}

type TUISelectItem

type TUISelectItem struct {
	ID   string
	Name string
	Desc string
}

func (TUISelectItem) Description

func (i TUISelectItem) Description() string

func (TUISelectItem) FilterValue

func (i TUISelectItem) FilterValue() string

func (TUISelectItem) Title

func (i TUISelectItem) Title() string

type TUISelectOneParams

type TUISelectOneParams struct {
	Name        string
	Description string
	Items       []TUISelectItem
}

type TUISelectOneResult

type TUISelectOneResult struct {
	SelectedID   string
	SelectedItem TUISelectItem
}

Directories

Path Synopsis
examples
flags command
flow command
hello command
subcommands command
internal
filepicker
Package filepicker provides a file picker component for Bubble Tea applications.
Package filepicker provides a file picker component for Bubble Tea applications.

Jump to

Keyboard shortcuts

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