commands

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DepArraysMatch

func DepArraysMatch(d1, d2 []*Dependency) bool

func FileExists

func FileExists(filename string) bool

func Kill

func Kill(cmd *exec.Cmd) error

func KindFlagMap

func KindFlagMap() map[string]string

func KindKeyMap

func KindKeyMap() map[string]string

func NewDummyAppConfig

func NewDummyAppConfig() *config.AppConfig

NewDummyAppConfig creates a new dummy AppConfig for testing

func NewDummyLog

func NewDummyLog() *logrus.Entry

NewDummyLog creates a new dummy Log for testing

func RunLineOutputCmd

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

func WrapError

func WrapError(err error) error

WrapError wraps an error for the sake of showing a stack trace at the top level the go-errors package, for some reason, does not return nil when you try to wrap a non-error, so we're just doing it here

Types

type Author

type Author struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	Url   string `json:"url"`
	// if a string rather than an object was given we'll store it in SingleLine
	SingleLine string
}

func (Author) ToString

func (a Author) ToString() string

type CommandView

type CommandView struct {
	// not super keen on having this dependency on gocui here but alas
	View      *gocui.View
	Cmd       *exec.Cmd
	Cancelled bool
}

func (*CommandView) Running

func (cv *CommandView) Running() bool

func (*CommandView) Status

func (cv *CommandView) Status() string

type CommandViewMap

type CommandViewMap map[string]*CommandView

type Dependency

type Dependency struct {
	Name              string
	Constraint        string
	LinkPath          string
	Present           bool
	PackageConfig     *PackageConfig
	Path              string
	Kind              string
	ParentPackagePath string
}

func (*Dependency) ConfigPath

func (d *Dependency) ConfigPath() string

func (*Dependency) ID

func (d *Dependency) ID() string

func (*Dependency) KindKey

func (d *Dependency) KindKey() string

func (*Dependency) Linked

func (d *Dependency) Linked() bool

type KindFlag

type KindFlag struct {
	Kind string
	Flag string
}

func KindFlags

func KindFlags() []KindFlag

type NpmManager

type NpmManager struct {
	Log       *logrus.Entry
	OSCommand *OSCommand
	Tr        *i18n.Localizer
	Config    config.AppConfigurer
	NpmRoot   string
}

NpmManager is our main git interface

func NewDummyNpmManager

func NewDummyNpmManager() *NpmManager

NewDummyNpmManager creates a new dummy NpmManager for testing

func NewDummyNpmManagerWithOSCommand

func NewDummyNpmManagerWithOSCommand(osCommand *OSCommand) *NpmManager

NewDummyNpmManagerWithOSCommand creates a new dummy NpmManager for testing

func NewNpmManager

func NewNpmManager(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer, config config.AppConfigurer) (*NpmManager, error)

NewNpmManager it runs git commands

func (*NpmManager) ChdirToPackageRoot

func (m *NpmManager) ChdirToPackageRoot() (bool, error)

func (*NpmManager) EditDepConstraint

func (m *NpmManager) EditDepConstraint(dep *Dependency, packageJsonPath string, constraint string) error

func (*NpmManager) EditOrAddScript

func (m *NpmManager) EditOrAddScript(scriptName string, packageJsonPath string, newName string, newCommand string) error

func (*NpmManager) GetDeps

func (m *NpmManager) GetDeps(currentPkg *Package, previousDeps []*Dependency) ([]*Dependency, error)

func (*NpmManager) GetPackages

func (m *NpmManager) GetPackages(paths []string, previousPackages []*Package) ([]*Package, error)

func (*NpmManager) GetTarballs

func (m *NpmManager) GetTarballs(currentPkg *Package) ([]*Tarball, error)

func (*NpmManager) IsLinked

func (m *NpmManager) IsLinked(name string, path string) (bool, error)

func (*NpmManager) RemoveScript

func (m *NpmManager) RemoveScript(scriptName string, packageJsonPath string) error

type OSCommand

type OSCommand struct {
	Log      *logrus.Entry
	Platform *Platform
	Config   config.AppConfigurer
	// contains filtered or unexported fields
}

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) 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) 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) FileType

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

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

func (*OSCommand) GetLazynpmPath

func (c *OSCommand) GetLazynpmPath() string

GetLazynpmPath 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) 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) 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 Package

type Package struct {
	Config PackageConfig
	Path   string
	// for when something is linked to the global node_modules folder
	LinkedGlobally bool
}

func (*Package) ConfigPath

func (p *Package) ConfigPath() string

func (*Package) ID

func (p *Package) ID() string

func (*Package) Scoped

func (p *Package) Scoped() bool

func (*Package) SortedDependencies

func (p *Package) SortedDependencies(previousDeps []*Dependency) []*Dependency

func (*Package) SortedScripts

func (p *Package) SortedScripts() []*Script

type PackageConfig

type PackageConfig struct {
	// this is the sha256 of the pakage.json file
	Sha                  []byte
	Name                 string
	Version              string
	License              string
	Description          string
	Homepage             string
	Main                 string
	Deprecated           bool
	Private              bool
	Files                []string
	Keywords             []string
	Os                   []string
	Cpu                  []string
	BundledDependencies  []string
	Scripts              map[string]string
	Directories          map[string]string
	Dependencies         map[string]string
	DevDependencies      map[string]string
	PeerDependencies     map[string]string
	OptionalDependencies map[string]string
	SortedDependencies   []*Dependency
	Engines              struct {
		Node string
		Npm  string
	}
	Repository   Repository
	Author       Author
	Contributors []Author
	Bugs         struct {
		Url string `json:"url"`
	}
}

func UnmarshalPackageConfig

func UnmarshalPackageConfig(r io.Reader, previousPackageConfig *PackageConfig) (*PackageConfig, error)

type Platform

type Platform struct {
	// contains filtered or unexported fields
}

Platform stores the os state

type Repository

type Repository struct {
	Type string `json:"type"`
	Url  string `json:"url"`
	// if a string rather than an object was given we'll store it in SingleLine
	SingleLine string
}

func (Repository) ToString

func (r Repository) ToString() string

type RunCommandOptions

type RunCommandOptions struct {
	EnvVars []string
}

type Script

type Script struct {
	Name              string
	Command           string
	ParentPackagePath string
}

func (*Script) ID

func (s *Script) ID() string

type Tarball

type Tarball struct {
	Name string
	Path string
}

func (*Tarball) ID

func (t *Tarball) ID() string

Jump to

Keyboard shortcuts

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