oscommands

package
v0.23.6 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src string, dst string) (err error)

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist. If destination already exists we'll clobber it. Symlinks are ignored and skipped.

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file. The file mode will be copied from the source and the copied data is synced/flushed to stable storage.

func Kill

func Kill(cmd *exec.Cmd) error

func RunCommandWithOutputLiveWrapper

func RunCommandWithOutputLiveWrapper(c *OSCommand, command string, output func(string) string) error

RunCommandWithOutputLiveWrapper runs a command and return every word that gets written in stdout Output is a function that executes by every word that gets read by bufio As return of output you need to give a string that will be written to stdin NOTE: If the return data is empty it won't written anything to stdin

func RunLineOutputCmd

func RunLineOutputCmd(cmd *exec.Cmd, onLine func(line string) (bool, error)) error

Types

type OSCommand

type OSCommand struct {
	Log                *logrus.Entry
	Platform           *Platform
	Config             config.AppConfigurer
	Command            func(string, ...string) *exec.Cmd
	BeforeExecuteCmd   func(*exec.Cmd)
	GetGlobalGitConfig func(string) (string, error)
	Getenv             func(string) string
}

OSCommand holds all the os commands

func NewDummyOSCommand

func NewDummyOSCommand() *OSCommand

NewDummyOSCommand creates a new dummy OSCommand for testing

func NewOSCommand

func NewOSCommand(log *logrus.Entry, config config.AppConfigurer) *OSCommand

NewOSCommand os command runner

func (*OSCommand) AppendLineToFile

func (c *OSCommand) AppendLineToFile(filename, line string) error

AppendLineToFile adds a new line in file

func (*OSCommand) CopyToClipboard

func (c *OSCommand) CopyToClipboard(str string) error

func (*OSCommand) CreateFileWithContent

func (c *OSCommand) CreateFileWithContent(path string, content string) error

CreateFileWithContent creates a file with the given content

func (*OSCommand) CreateTempFile

func (c *OSCommand) CreateTempFile(filename, content string) (string, error)

CreateTempFile writes a string to a new temp file and returns the file's name

func (*OSCommand) DetectUnamePass

func (c *OSCommand) DetectUnamePass(command string, promptUserForCredential func(string) string) error

DetectUnamePass detect a username / password / passphrase question in a command promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back

func (*OSCommand) EditFile

func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error)

EditFile opens a file in a subprocess using whatever editor is available, falling back to core.editor, VISUAL, EDITOR, then vi

func (*OSCommand) ExecutableFromString

func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd

ExecutableFromString takes a string like `git status` and returns an executable command for it

func (*OSCommand) FileExists

func (c *OSCommand) FileExists(path string) (bool, error)

FileExists checks whether a file exists at the specified path

func (*OSCommand) FileType

func (c *OSCommand) FileType(path string) string

FileType tells us if the file is a file, directory or other

func (*OSCommand) GetLazygitPath

func (c *OSCommand) GetLazygitPath() string

GetLazygitPath returns the path of the currently executed file

func (*OSCommand) OpenFile

func (c *OSCommand) OpenFile(filename string) error

OpenFile opens a file with the given

func (c *OSCommand) OpenLink(link string) error

OpenLink opens a file with the given

func (*OSCommand) PipeCommands

func (c *OSCommand) PipeCommands(commandStrings ...string) error

PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C

func (*OSCommand) PrepareSubProcess

func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *exec.Cmd

PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it TODO: see if this needs to exist, given that ExecutableFromString does the same things

func (*OSCommand) Quote

func (c *OSCommand) Quote(message string) string

Quote wraps a message in platform-specific quotation marks

func (*OSCommand) Remove

func (c *OSCommand) Remove(filename string) error

Remove removes a file or directory at the specified path

func (*OSCommand) RunCommand

func (c *OSCommand) RunCommand(formatString string, formatArgs ...interface{}) error

RunCommand runs a command and just returns the error

func (*OSCommand) RunCommandWithOptions

func (c *OSCommand) RunCommandWithOptions(command string, options RunCommandOptions) error

func (*OSCommand) RunCommandWithOutput

func (c *OSCommand) RunCommandWithOutput(formatString string, formatArgs ...interface{}) (string, error)

RunCommandWithOutput wrapper around commands returning their output and error NOTE: If you don't pass any formatArgs we'll just use the command directly, however there's a bizarre compiler error/warning when you pass in a formatString with a percent sign because it thinks it's supposed to be a formatString when in that case it's not. To get around that error you'll need to define the string in a variable and pass the variable into RunCommandWithOutput.

func (*OSCommand) RunCommandWithOutputLive

func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) error

RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper

func (*OSCommand) RunCommandWithOutputWithOptions

func (c *OSCommand) RunCommandWithOutputWithOptions(command string, options RunCommandOptions) (string, error)

func (*OSCommand) RunCustomCommand

func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd

RunCustomCommand returns the pointer to a custom command

func (*OSCommand) RunDirectCommand

func (c *OSCommand) RunDirectCommand(command string) (string, error)

RunDirectCommand wrapper around direct commands

func (*OSCommand) RunExecutable

func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error

RunExecutable runs an executable file and returns an error if there was one

func (*OSCommand) RunExecutableWithOutput

func (c *OSCommand) RunExecutableWithOutput(cmd *exec.Cmd) (string, error)

RunExecutableWithOutput runs an executable file and returns its output

func (*OSCommand) RunPreparedCommand

func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error

RunPreparedCommand takes a pointer to an exec.Cmd and runs it this is useful if you need to give your command some environment variables before running it

func (*OSCommand) SetBeforeExecuteCmd

func (c *OSCommand) SetBeforeExecuteCmd(cmd func(*exec.Cmd))

func (*OSCommand) SetCommand

func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd)

SetCommand sets the command function used by the struct. To be used for testing only

func (*OSCommand) ShellCommandFromString

func (c *OSCommand) ShellCommandFromString(commandStr string) *exec.Cmd

ShellCommandFromString takes a string like `git commit` and returns an executable shell command for it

func (*OSCommand) Unquote

func (c *OSCommand) Unquote(message string) string

Unquote removes wrapping quotations marks if they are present this is needed for removing quotes from staged filenames with spaces

type Platform

type Platform struct {
	OS                   string
	CatCmd               string
	Shell                string
	ShellArg             string
	EscapedQuote         string
	OpenCommand          string
	OpenLinkCommand      string
	FallbackEscapedQuote string
}

Platform stores the os state

type RunCommandOptions

type RunCommandOptions struct {
	EnvVars []string
}

Jump to

Keyboard shortcuts

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