commandline

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownCommands = []string{
	"SyncRemoteToLocal",
	"SyncLocalToRemote",
}

KnownCommands is the list of all recognized command names.

Functions

func FuzzyMatchString

func FuzzyMatchString(query, target string) (int, []int, bool)

FuzzyMatchString checks if query fuzzy-matches target (case-insensitive subsequence). Returns score, matched byte indices, and whether all query chars were found.

func SplitPath

func SplitPath(partial string) (dir, base string)

SplitPath splits a partial path into directory prefix and filename base.

"reports/q1"  → ("reports/", "q1")
"/tmp/loc"    → ("/tmp/", "loc")
"reports/"    → ("reports/", "")
""            → ("", "")

Types

type Command

type Command struct {
	Kind CommandKind
	Args []string // positional arguments after the command name
	Raw  string   // original input
}

Command is the result of parsing a raw command-line string.

func Parse

func Parse(raw string) Command

Parse tokenizes and parses a raw command string (without the leading ':'). Returns a Command with Kind=CmdUnknown if the command is not recognized.

type CommandKind

type CommandKind int

CommandKind identifies the parsed command type.

const (
	CmdUnknown           CommandKind = iota
	CmdSyncRemoteToLocal             // SyncRemoteToLocal <remote_dir> <local_dir>
	CmdSyncLocalToRemote             // SyncLocalToRemote <local_dir> <remote_dir>
)

type FuzzyResult

type FuzzyResult struct {
	Command      string
	Score        int
	MatchIndices []int // byte indices in Command where query chars matched
}

FuzzyResult holds a fuzzy match with scoring and match positions.

func FuzzyMatch

func FuzzyMatch(query string) []FuzzyResult

FuzzyMatch returns known commands whose names fuzzy-match the query (characters appear in order as a subsequence, case-insensitive). Results are sorted by score descending. Returns nil if query is empty.

type InputContext

type InputContext struct {
	Command     string      // first token (if complete), else ""
	CommandKind CommandKind // parsed kind of the command
	ArgIndex    int         // 0-based arg being edited; -1 = still typing command
	Partial     string      // incomplete text being typed for current position
}

InputContext describes the editing position within a command-line input.

func AnalyzeInput

func AnalyzeInput(raw string) InputContext

AnalyzeInput examines raw command-line text and returns the editing context. The cursor is assumed to be at the end of raw.

Jump to

Keyboard shortcuts

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