command

package
v0.4.17 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PositionOnlyPrefix = '.'
	NameOnlyPrefix     = ':'
)

Variables

View Source
var (
	ErrNoKeywords            = errors.New("no keywords")
	ErrEmptyKeyword          = errors.New("empty keyword")
	ErrDuplicateKeyword      = errors.New("duplicate keyword definition")
	ErrUnknownCommand        = errors.New("unknown command")
	ErrUnexpectedPreposition = errors.New("unexpected preposition")
	ErrUnexpectedArgument    = errors.New("unexpected argument")
	ErrDanglingPreposition   = errors.New("dangling preposition")
	ErrMissingColumns        = errors.New("missing columns")
)
View Source
var DefaultKeywords = Keywords{

	Move:   Keyword{"move", "mv"},
	Insert: Keyword{"insert", "ins", "prepend"},
	Append: Keyword{"append", "add"},
	Delete: Keyword{"delete", "del", "remove", "rm"},
	Sort:   Keyword{"sort"},

	Before: Keyword{"before"},
	After:  Keyword{"after"},
	With:   Keyword{"with"},

	First: Keyword{"first"},
	Last:  Keyword{"last"},
}

Functions

This section is empty.

Types

type BuilderBase

type BuilderBase struct {
	Keywords
}

func (*BuilderBase) AddArg

func (b *BuilderBase) AddArg(string)

func (*BuilderBase) AddColumnLocator

func (b *BuilderBase) AddColumnLocator(column.Locator)

func (*BuilderBase) AddPreposition

func (b *BuilderBase) AddPreposition(string)

func (*BuilderBase) WantArg

func (b *BuilderBase) WantArg() bool

func (*BuilderBase) WantColumn

func (b *BuilderBase) WantColumn() bool

func (*BuilderBase) WantPreposition

func (b *BuilderBase) WantPreposition(string) bool

type Command

type Command interface {
	Name() string
	Apply(ConfigAPI)
}

type ConfigAPI

type ConfigAPI interface {
	SetPrefix(...string)
	Index() column.Index
	SetIndex(column.Index)
	FillColumns([]column.Locator, string)
}

type Delete

type Delete struct {
	Keyword        string
	ColumnLocators []column.Locator
}

func (*Delete) Apply

func (cmd *Delete) Apply(cfg ConfigAPI)

func (*Delete) Name

func (cmd *Delete) Name() string

func (*Delete) String

func (cmd *Delete) String() string

type DeleteBuilder

type DeleteBuilder struct {
	BuilderBase
	// contains filtered or unexported fields
}

func (*DeleteBuilder) AddColumnLocator

func (b *DeleteBuilder) AddColumnLocator(loc column.Locator)

func (*DeleteBuilder) Command

func (b *DeleteBuilder) Command() (Command, error)

func (*DeleteBuilder) Name

func (b *DeleteBuilder) Name() string

func (*DeleteBuilder) SetKeyword

func (b *DeleteBuilder) SetKeyword(kw string)

func (*DeleteBuilder) WantColumn

func (b *DeleteBuilder) WantColumn() bool

type Insert

type Insert struct {
	Keyword        string           // keyword used to trigger command
	Preposition    string           // preposition used on this command
	ColumnLocators []column.Locator // column names to insert
	After          bool             // position +1 (after search) if true
	Target         column.Locator   // "first", "last" or column name
	// contains filtered or unexported fields
}

prepend == Insert{Columns: ..., Verb: "before", Target: ...} append == Insert{Columns: ..., Verb: "after", Target: ...}

func (*Insert) Apply

func (cmd *Insert) Apply(cfg ConfigAPI)

func (*Insert) Name

func (cmd *Insert) Name() string

func (*Insert) String

func (cmd *Insert) String() string

type InsertBuilder

type InsertBuilder struct {
	BuilderBase
	// contains filtered or unexported fields
}

func (*InsertBuilder) AddColumnLocator

func (b *InsertBuilder) AddColumnLocator(id column.Locator)

func (*InsertBuilder) AddPreposition

func (b *InsertBuilder) AddPreposition(arg string)

func (*InsertBuilder) Command

func (b *InsertBuilder) Command() (Command, error)

func (*InsertBuilder) Name

func (b *InsertBuilder) Name() string

func (*InsertBuilder) SetKeyword

func (b *InsertBuilder) SetKeyword(kw string)

func (*InsertBuilder) WantColumn

func (b *InsertBuilder) WantColumn() bool

func (*InsertBuilder) WantPreposition

func (b *InsertBuilder) WantPreposition(arg string) bool

type Keyword

type Keyword []string

func (Keyword) Aliases

func (kw Keyword) Aliases() []string

func (Keyword) Is

func (kw Keyword) Is(name string) bool

func (Keyword) Name

func (kw Keyword) Name() string

type Keywords

type Keywords struct {
	// commands
	Move   Keyword `json:"move"`
	Insert Keyword `json:"insert"`
	Append Keyword `json:"append"`
	Delete Keyword `json:"delete"`
	Sort   Keyword `json:"sort"`
	// Prefix Keyword `json:"prefix"`	// TODO: 2026-02-23 needs to be applied before parsing - currently commands only affect rendering
	// Fill  Keyword `json:"fill"`	// TODO: 2026-02-23 Not Yet Implemented
	// Clear Keyword `json:"clear"`	// TODO: 2026-02-23 Not Yet Implemented
	// prepositions
	Before Keyword `json:"before"`
	After  Keyword `json:"after"`
	With   Keyword `json:"with"`
	// column locators
	First Keyword `json:"first"`
	Last  Keyword `json:"last"`
}

type Move

type Move struct {
	Keyword        string
	Preposition    string
	ColumnLocators []column.Locator // columns to be moved
	After          bool             // move before (default, false) or after (true) the target
	Target         column.Locator   // insertion point (default: first column)
}

Move shifts a number of columns to a new position while rendering a table.

Example: psv mv wip todo done before first

  • would move the "wip", "todo" and "done" columns to the left of the table
  • the words "mv", "before" and "first" are keywords

Algorithm:

psv mv e a d before c
| a | b | c | d | e |
| 0 | 1 | 2 | 3 | 4 |

1. locate target
  - "c" => 2

2. locate movers
  - [ 4, 0, 3 ]

3. build new index
  - pos < target && pos not in movers => keep
  - pos == target => insert movers
  - pos > target && pos not in movers => keep

func (*Move) Apply

func (cmd *Move) Apply(cfg ConfigAPI)

func (*Move) Name

func (cmd *Move) Name() string

func (*Move) String

func (cmd *Move) String() string

type MoveBuilder

type MoveBuilder struct {
	BuilderBase
	// contains filtered or unexported fields
}

func (*MoveBuilder) AddColumnLocator

func (b *MoveBuilder) AddColumnLocator(loc column.Locator)

func (*MoveBuilder) AddPreposition

func (b *MoveBuilder) AddPreposition(arg string)

func (*MoveBuilder) Command

func (b *MoveBuilder) Command() (Command, error)

func (*MoveBuilder) Name

func (b *MoveBuilder) Name() string

func (*MoveBuilder) SetKeyword

func (b *MoveBuilder) SetKeyword(kw string)

func (*MoveBuilder) WantColumn

func (b *MoveBuilder) WantColumn() bool

func (*MoveBuilder) WantPreposition

func (b *MoveBuilder) WantPreposition(arg string) bool

type Parser

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

func New

func New(keywords Keywords) (*Parser, error)

func (*Parser) Parse

func (p *Parser) Parse(args []string) ([]Command, error)

type Prefix

type Prefix struct {
	Keyword string   // the keyword used to trigger this command
	Symbols []string // symbols to be treated as valid table prefixes
}

func (*Prefix) Apply

func (cmd *Prefix) Apply(cfg ConfigAPI)

func (*Prefix) Name

func (cmd *Prefix) Name() string

func (*Prefix) String

func (cmd *Prefix) String() string

type PrefixBuilder

type PrefixBuilder struct {
	BuilderBase
	// contains filtered or unexported fields
}

func (*PrefixBuilder) AddArg

func (b *PrefixBuilder) AddArg(arg string)

func (*PrefixBuilder) Command

func (b *PrefixBuilder) Command() (Command, error)

func (*PrefixBuilder) Name

func (b *PrefixBuilder) Name() string

func (*PrefixBuilder) SetKeyword

func (b *PrefixBuilder) SetKeyword(kw string)

func (*PrefixBuilder) WantArg

func (b *PrefixBuilder) WantArg() bool

type Sort

type Sort struct {
	Keyword        string
	ColumnLocators []column.Locator
}

Sort resets the sorting flags of the columns in a column index.

Steps:

  1. remove all sorting flags from all columns
  2. prepare a list of column indexes - Sort by requested columns first, then by all remaining columns in their present order
  3. enable sorting and prioritize columns according to their position in the column index - contiguous column indexes share the same priority - priorities are only set if there is more than 1 contiguous group of columns

func (*Sort) Apply

func (cmd *Sort) Apply(cfg ConfigAPI)

Apply adds sorting hints to a table's columns - sorting is enabled on all columns - existing sort direction is RETAINED - existing sort priorities are reset to cater for the new comparison order

func (*Sort) Name

func (cmd *Sort) Name() string

func (*Sort) String

func (cmd *Sort) String() string

type SortBuilder

type SortBuilder struct {
	BuilderBase
	// contains filtered or unexported fields
}

func (*SortBuilder) AddColumnLocator

func (b *SortBuilder) AddColumnLocator(loc column.Locator)

func (*SortBuilder) Command

func (b *SortBuilder) Command() (Command, error)

func (*SortBuilder) Name

func (b *SortBuilder) Name() string

func (*SortBuilder) SetKeyword

func (b *SortBuilder) SetKeyword(kw string)

func (*SortBuilder) WantColumn

func (b *SortBuilder) WantColumn() bool

Jump to

Keyboard shortcuts

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