fssh

package module
v0.0.0-...-a975cec Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 21 Imported by: 0

README

fssh

fssh is a shell for multiple file systems.

Feature

  • Multiple file systems
    • local
    • amazon s3
    • google cloud storage
  • Command history
  • Simple auto complete

Install

go install github.com/jarxorg/fssh/cmd/fssh@latest

Examples

Help
fssh

.> help
Usage:
  help ([command])
Commands:
  !		    shell escape
  cat		concatenate and print files
  cd		change directory
  cp		copy files
  env		prints or sets environment
  exit		exit fssh
  ls		list directory contents
  pwd		print working directory name
  rm		remove files
Connect s3 and copy to gcs
fssh s3://[S3-Bucket]/

s3://[S3-Bucket]> ls
dir1/
dir2/
file1.txt
file2.txt

s3://[S3-Bucket]> cp -r dir1 gs://[GCS-Bucket]/

Credentianls

AWS

fssh tries to use the AWS default authentication for accessing S3 buckets.

See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

If you are using non-default AWS authentication, here is an example.

fssh
./> env AWS_ACCESS_KEY_ID=[your access key]
./> env AWS_SECRET_ACCESS_KEY=[your access secret key]
./> env AWS_REGION=[your region]
./> cd s3://[S3-Bucket]/
s3://[S3-Bucket]>
AWS_PROFILE=custom fssh s3://[S3-Bucket]/
s3://[S3-Bucket]>
Google Cloud

fssh tries to use the Google Cloud default credentials for accessing GCS buckets.

See https://cloud.google.com/docs/authentication/application-default-credentials

If you are using non-default Google credential, here is an example.

fssh
./> env GOOGLE_APPLICATION_CREDENTIALS=path-to-credential.json
./> cd gs://[GCS-Bucket]
gs://[GCS-Bucket]>
GOOGLE_APPLICATION_CREDENTIALS=path-to-credential.json fssh gs://[GCS-Bucket]
gs://[GCS-Bucket]>

Documentation

Index

Constants

View Source
const ShellName = "fssh"

ShellName is "fssh".

Variables

View Source
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 DisplaySize

func DisplaySize(size int64) string

DisplaySize returns summary of size.

func IsCurrentPath

func IsCurrentPath(name string) bool

IsCurrentPath checks the specified name has ":/"

func IsGlobPattern

func IsGlobPattern(pattern string) bool

IsGlobPattern checks pattern contains glob pattern.

func Main

func Main(osArgs []string) error

Main runs shell.

func ParseArgs

func ParseArgs(line string) []string

ParseArgs parses the specified line to args.

func ParseURI

func ParseURI(uri string) (protocol, host, filename string, err error)

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 SliceClone

func SliceClone[T comparable](src []T) []T

SliceClone clones a slice.

func SortedCommandNames

func SortedCommandNames() []string

SortedCommandNames returns sorted command names from registered commands.

func WithPrefixes

func WithPrefixes(items []string, prefix string) []string

WithPrefixes set prefix to each items.

func WithSuffixes

func WithSuffixes(items []string, suffix string) []string

WithSuffixes set suffix to each items.

Types

type AutoCompleterFunc

type AutoCompleterFunc func(sh *Shell, arg string) ([]string, error)

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

func AquireCommand(name string) Command

AquireCommand returns an Command instance from command pool.

type FS

type FS wfs.WriteFileFS

FS is writable FS.

func NewDirFS

func NewDirFS(dirUrl string) (fsys FS, protocol string, host string, dir string, err error)

NewDirFS parses dirUrl and creates a new FS according to the protocol.

func NewFS

func NewFS(filenameUrl string) (fsys FS, protocol string, host string, filename string, err error)

NewFS parses nameUrl and creates a new FS according to the protocol.

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.

func (*GlobPrefixMatcher) Matches

func (m *GlobPrefixMatcher) Matches(sh *Shell, prefix string) ([]string, error)

Matches returns files and directories that match the prefix.

func (*GlobPrefixMatcher) Reset

func (m *GlobPrefixMatcher) Reset()

Reset clears internal cache.

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 NewShell

func NewShell(dirUrl string) (*Shell, error)

NewShell creates a new Shell.

func (*Shell) Close

func (sh *Shell) Close() error

Close closes the shell.

func (*Shell) DirWithProtocol

func (sh *Shell) DirWithProtocol() string

DirWithProtocol returns the current directory held by the shell.

func (*Shell) ExecCommand

func (sh *Shell) ExecCommand(args []string) error

ExecCommand executes a command.

func (*Shell) Run

func (sh *Shell) Run() error

Run runs the shell.

func (*Shell) SubDirFS

func (sh *Shell) SubDirFS(dirUrl string) (FS, string, error)

SubFS returns the FS and related path. If the dirUrl has protocol then this creates a new FS.

func (*Shell) SubFS

func (sh *Shell) SubFS(filenameUrl string) (FS, string, error)

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.

func (*Shell) Usage

func (sh *Shell) Usage(w io.Writer)

Usage prints the usage to the specified writer..

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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