Documentation ¶
Index ¶
- Constants
- Variables
- func DeregisterNewCommandFunc(name string)
- func DisplaySize(size int64) string
- func IsCurrentPath(name string) bool
- func IsGlobPattern(pattern string) bool
- func Main(osArgs []string) error
- func ParseArgs(line string) []string
- func ParseURI(uri string) (protocol, host, filename string, err error)
- func RegisterNewCommandFunc(fn NewCommandFunc)
- func ReleaseCommand(cmd Command)
- func SliceClone[T comparable](src []T) []T
- func SortedCommandNames() []string
- func WithPrefixes(items []string, prefix string) []string
- func WithSuffixes(items []string, suffix string) []string
- type AutoCompleterFunc
- type Command
- type FS
- type GlobPrefixMatcher
- type NewCommandFunc
- type PrefixMatcher
- type Shell
- func (sh *Shell) Close() error
- func (sh *Shell) DirWithProtocol() string
- func (sh *Shell) ExecCommand(args []string) error
- func (sh *Shell) Run() error
- func (sh *Shell) SubDirFS(dirUrl string) (FS, string, error)
- func (sh *Shell) SubFS(filenameUrl string) (FS, string, error)
- func (sh *Shell) UpdatePrompt()
- func (sh *Shell) Usage(w io.Writer)
Constants ¶
const ShellName = "fssh"
ShellName is "fssh".
Variables ¶
var ErrExit = errors.New("exit")
ErrExit represents an exit error. If this error is detected then the shell will terminate.
Functions ¶
func DeregisterNewCommandFunc ¶
func DeregisterNewCommandFunc(name string)
DeregisterNewCommandFunc deregisters a named NewCommandFunc.
func IsCurrentPath ¶
IsCurrentPath checks the specified name has ":/"
func IsGlobPattern ¶
IsGlobPattern checks pattern contains glob pattern.
func ParseURI ¶
ParseURI parses the specified uri to protocol, host, filename. If the uri starts with ~~ it is replaced with the local current filename. If the uri starts with ~, it is replaced with the local home filename.
func RegisterNewCommandFunc ¶
func RegisterNewCommandFunc(fn NewCommandFunc)
RegisterNewCommandFunc registers a specified NewCommandFunc.
func ReleaseCommand ¶
func ReleaseCommand(cmd Command)
ReleaseCommand releases a acquired Command via AquireCommand to command pool.
func SortedCommandNames ¶
func SortedCommandNames() []string
SortedCommandNames returns sorted command names from registered commands.
func WithPrefixes ¶
WithPrefixes set prefix to each items.
func WithSuffixes ¶
WithSuffixes set suffix to each items.
Types ¶
type AutoCompleterFunc ¶
AutoCompleterFunc represent a function for auto completion.
type Command ¶
type Command interface { // Name returns the name of a command. Name() string // Description returns the description of a command. Description() string // FlagSet returns the flagSet of a command. FlagSet() *flag.FlagSet // Exec executes a command. Exec(sh *Shell) error // Usage writes help usage. Usage(w io.Writer) // AutoCompleter returns a AutoCompleter if the command supports auto completion. AutoCompleter() AutoCompleterFunc // Reset resets the command status. This is called after Exec. Reset() }
Command is an interface that defines a shell command.
func AquireCommand ¶
AquireCommand returns an Command instance from command pool.
type FS ¶
type FS wfs.WriteFileFS
FS is writable FS.
type GlobPrefixMatcher ¶
type GlobPrefixMatcher struct {
// contains filtered or unexported fields
}
func (*GlobPrefixMatcher) MatchDirs ¶
func (m *GlobPrefixMatcher) MatchDirs(sh *Shell, prefix string) ([]string, error)
Matches returns directories that match the prefix.
func (*GlobPrefixMatcher) MatchFiles ¶
func (m *GlobPrefixMatcher) MatchFiles(sh *Shell, prefix string) ([]string, error)
Matches returns files that match the prefix.
type NewCommandFunc ¶
type NewCommandFunc func() Command
NewCommandFunc represents a function to create a new command.
type PrefixMatcher ¶
type PrefixMatcher interface { // Matches returns files and directories that match the prefix. Matches(sh *Shell, prefix string) ([]string, error) // Matches returns files that match the prefix. MatchFiles(sh *Shell, prefix string) ([]string, error) // Matches returns directories that match the prefix. MatchDirs(sh *Shell, prefix string) ([]string, error) // Reset is called when the shell status was updated. Reset() }
PrefixMatcher provides a functions to match prefix.
type Shell ¶
type Shell struct { Stdout io.Writer Stderr io.Writer FS wfs.WriteFileFS Protocol string Host string Dir string PrefixMatcher PrefixMatcher // contains filtered or unexported fields }
Shell reads stdin, interprets lines, and executes commands.
func (*Shell) DirWithProtocol ¶
DirWithProtocol returns the current directory held by the shell.
func (*Shell) ExecCommand ¶
ExecCommand executes a command.
func (*Shell) SubDirFS ¶
SubFS returns the FS and related path. If the dirUrl has protocol then this creates a new FS.
func (*Shell) SubFS ¶
SubFS returns the FS and related path. If the dirUrl has protocol then this creates a new FS.
func (*Shell) UpdatePrompt ¶
func (sh *Shell) UpdatePrompt()
UpdatePrompt updates the command line prompt.