Documentation ¶
Index ¶
- Constants
- Variables
- func Apt(virtOS vos.VOS) int
- func BuiltinProcessResolver(command string) vos.ProcessFunc
- func BytesToHuman(bytes int64) string
- func Cat(virtOS vos.VOS) int
- func Cd(s *Shell, args []string) int
- func Chmod(virtOS vos.VOS) int
- func ChmodApplyMode(mode string, orig fs.FileMode) (fs.FileMode, error)
- func Clear(virtOS vos.VOS) int
- func Curl(virtOS vos.VOS) int
- func Dircolor(fileInfo os.FileInfo) *fcolor.Color
- func Echo(virtOS vos.VOS) int
- func Env(virtOS vos.VOS) int
- func Exit(s *Shell, args []string) int
- func Free(virtOS vos.VOS) int
- func Grep(virtOS vos.VOS) int
- func Help(s *Shell, args []string) int
- func History(s *Shell, args []string) int
- func Hostname(virtOS vos.VOS) int
- func Id(virtOS vos.VOS) int
- func Ifconfig(virtOS vos.VOS) int
- func Ip(virtOS vos.VOS) int
- func Last(virtOS vos.VOS) int
- func Ls(virtOS vos.VOS) int
- func Mail(virtOS vos.VOS) int
- func Mkdir(virtOS vos.VOS) int
- func NewWcCount(name string, fd io.Reader) (*wcCount, error)
- func Nice(virtOS vos.VOS) int
- func NopBuiltin(s *Shell, args []string) int
- func Passwd(virtualOS vos.VOS) int
- func Ps(virtOS vos.VOS) int
- func Pwd(virtOS vos.VOS) int
- func Reboot(virtOS vos.VOS) int
- func Reset(virtOS vos.VOS) int
- func Rm(virtOS vos.VOS) int
- func Rmdir(virtOS vos.VOS) int
- func RunShell(virtualOS vos.VOS) int
- func Scp(virtOS vos.VOS) int
- func Sudo(s *Shell, args []string) int
- func Tar(virtOS vos.VOS) int
- func Touch(virtOS vos.VOS) int
- func UidResolver(virtOS vos.VOS) (resolver func(int) string)
- func Uname(virtOS vos.VOS) int
- func Unset(s *Shell, args []string) int
- func Unzip(virtOS vos.VOS) int
- func Uptime(virtOS vos.VOS) int
- func W(virtOS vos.VOS) int
- func Wc(virtOS vos.VOS) int
- func Wget(virtOS vos.VOS) int
- func Which(virtOS vos.VOS) int
- func Whoami(virtOS vos.VOS) int
- type ColorPrinter
- type CommandEntry
- type LsColorTest
- type NoOpCommand
- type Shell
- type ShellBuiltin
- type ShellBuiltinFunc
- type SimpleCommand
- func (s *SimpleCommand) Flags() *getopt.Set
- func (s *SimpleCommand) LogProgramError(virtOS vos.VOS, err error)
- func (s *SimpleCommand) PrintHelp(w io.Writer)
- func (s *SimpleCommand) Run(virtOS vos.VOS, callback func() int) int
- func (s *SimpleCommand) RunE(virtOS vos.VOS, callback func() error) int
- func (s *SimpleCommand) RunEachArg(virtOS vos.VOS, callback func(string) error) int
- func (s *SimpleCommand) RunEachFileOrStdin(virtOS vos.VOS, files []string, callback func(name string, fd io.Reader) error) int
Examples ¶
Constants ¶
const ( ModeMaskUser fs.FileMode = 0700 ModeMaskGroup = 0070 ModeMaskOther = 0007 ModeMaskAll = ModeMaskUser | ModeMaskGroup | ModeMaskOther ModeRead fs.FileMode = 0444 ModeWrite = 0222 ModeExec = 0111 ChmodMask = ModeMaskAll )
const ( EnvHome = "HOME" EnvPWD = "PWD" EnvPath = "PATH" EnvPrompt = "PS1" EnvHostname = "HOSTNAME" EnvUser = "USER" EnvUID = "UID" DefaultColorPrompt = `\033[01;32m\u@\h\033[00m:\033[01;34m\w\033[00m\$ ` DefaultPrompt = `\u@\h:\w\$ ` )
Variables ¶
var ( ColorBoldBlue = color.New(color.FgBlue, color.Bold) ColorBoldGreen = color.New(color.FgGreen, color.Bold) ColorBoldCyan = fcolor.New(color.FgCyan, color.Bold) ColorBoldRed = color.New(color.FgRed, color.Bold) )
var AllBuiltins = make(map[string]ShellBuiltin)
AllBuiltins holds a list of all registered shell builtins
Functions ¶
func BuiltinProcessResolver ¶
func BuiltinProcessResolver(command string) vos.ProcessFunc
BuiltinProcessResolver implemnts vos.ProcessResolver, it returns the builtin command with the given path or nil if none exists.
func BytesToHuman ¶
Example ¶
// < 1k is presented directly fmt.Println(BytesToHuman(512)) // Multiples > 10 are shown without decimal. fmt.Println(BytesToHuman(23 * 10e8)) // Multiples < 10 are shown with decimal. fmt.Println(BytesToHuman(5 * 1024))
Output: 512 23G 5.1K
func Cat ¶
Cat implements the POSIX cat command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/
func Chmod ¶
Chmod implements a POSIX chmod command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/chmod.html#tag_20_17
func Env ¶
Env implements the POSIX env command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/env.html
func Grep ¶
Grep implements the POSIX grep command.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html
func Id ¶
Id implements a the POSIX id command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/id.html
func Mail ¶
Mail implements a no-op POSIX mail command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/mailx.html
func Mkdir ¶
Mkdir implements a POSIX mkdir command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/mkdir.html
func Nice ¶
Nice implements a fake POSIX nice command.
https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/utilities/nice.html
func NopBuiltin ¶
func Wc ¶
Wc implements the POSIX command by the same name. https://pubs.opengroup.org/onlinepubs/009695399/utilities/wc.html
Types ¶
type ColorPrinter ¶
type ColorPrinter struct {
// contains filtered or unexported fields
}
func (*ColorPrinter) Init ¶
func (c *ColorPrinter) Init(flags *getopt.Set, virtOS vos.VOS)
Init sets up the flag and virtual OS to determine the color output.
func (*ColorPrinter) ShouldColor ¶
func (c *ColorPrinter) ShouldColor() bool
type CommandEntry ¶
type CommandEntry struct { Names []string Proc vos.ProcessFunc }
func ListBuiltinCommands ¶
func ListBuiltinCommands() []CommandEntry
type LsColorTest ¶
type LsColorTest struct {
// contains filtered or unexported fields
}
type NoOpCommand ¶
No-op commands.
func (*NoOpCommand) ToCommand ¶
func (c *NoOpCommand) ToCommand() vos.ProcessFunc
Convert the no-op command description to a functioning command.
type Shell ¶
type ShellBuiltin ¶
type ShellBuiltinFunc ¶
type SimpleCommand ¶
type SimpleCommand struct { // Use holds a one line usage string Use string // Short holds a sone line description of the command. Short string // ShowHelp sets whether help is displayed or not. // If this is non-nil when Run() is called, then the default help flag isn't // added. ShowHelp *bool // NeverBail skips interacting with stdout/stderr on failure and // always runs the callback. NeverBail bool // contains filtered or unexported fields }
func (*SimpleCommand) Flags ¶
func (s *SimpleCommand) Flags() *getopt.Set
Flags gets the command's flag set.
func (*SimpleCommand) LogProgramError ¶
func (s *SimpleCommand) LogProgramError(virtOS vos.VOS, err error)
Log a program error to stderr in the form "program name: error message"
func (*SimpleCommand) PrintHelp ¶
func (s *SimpleCommand) PrintHelp(w io.Writer)
PrintHelp writes help for the command to the given writer.
func (*SimpleCommand) Run ¶
func (s *SimpleCommand) Run(virtOS vos.VOS, callback func() int) int
Run the command, if flag parsing was succcessful call the callback.
func (*SimpleCommand) RunE ¶
func (s *SimpleCommand) RunE(virtOS vos.VOS, callback func() error) int
RunE runs the callback and converts the error into a return value and message.
func (*SimpleCommand) RunEachArg ¶
RunEachArg runs the callback for every supplied arg.
Source Files ¶
- aaa_noop.go
- apt.go
- base.go
- cat.go
- chmod.go
- clear.go
- curl.go
- echo.go
- env.go
- free.go
- grep.go
- hostname.go
- id.go
- last.go
- ls.go
- mail.go
- mkdir.go
- nettools.go
- nice.go
- passwd.go
- ps.go
- pwd.go
- reboot.go
- reset.go
- rm.go
- rmdir.go
- scp.go
- shell.go
- shell_builtins.go
- tar.go
- touch.go
- uname.go
- unzip.go
- uptime.go
- w.go
- wc.go
- wget.go
- which.go
- whoami.go