snippet

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SHELL_BASH        = "bash"
	SHELL_ZSH         = "zsh"
	SHELL_FISH        = "fish"
	SHELL_UNSUPPORTED = "unsupported"
)
View Source
const (
	EXPORT_TYPE_JSON  = "json"
	EXPORT_TYPE_SHELL = "shell"
)

Variables

View Source
var (
	MissingDefaultValueError = errors.New("missing default value for template field")
	InvalidStepRangeError    = errors.New("step range specified is invalid")
)
View Source
var TempHistFile = "/tmp/corgi.hist"
View Source
var TemplateParamsRegex = `<([^(<>)]+)>`

Functions

func FillTemplates

func FillTemplates(c string, tfMap *TemplateFieldMap) string

func ParseFileToStringArray

func ParseFileToStringArray(filePath string, parser CommandParser) ([]string, error)

func ReadShellHistory

func ReadShellHistory() ([]string, error)

func RemoveHistFile

func RemoveHistFile() error

func SetUpHistFile

func SetUpHistFile(histCmds []string) error

Types

type Answerable

type Answerable interface {
	AskQuestion(options ...interface{}) error
}

type BashCmdParser

type BashCmdParser struct{}

func (BashCmdParser) Parse

func (b BashCmdParser) Parse(line string) string

type CommandParser

type CommandParser interface {
	Parse(string) string
}

func GetCmdParser

func GetCmdParser(shellType string) (CommandParser, error)

type FishCmdParser added in v0.2.3

type FishCmdParser struct{}

func (FishCmdParser) Parse added in v0.2.3

func (f FishCmdParser) Parse(line string) string

type Snippet

type Snippet struct {
	Title string      `json:"title"`
	Steps []*StepInfo `json:"steps"`
	// contains filtered or unexported fields
}

func LoadSnippet

func LoadSnippet(filePath string) (*Snippet, error)

func NewSnippet

func NewSnippet(title string, cmds []string) (*Snippet, error)

func (*Snippet) AskQuestion

func (snippet *Snippet) AskQuestion(options ...interface{}) error

func (*Snippet) BuildTemplateFieldMap

func (snippet *Snippet) BuildTemplateFieldMap() TemplateFieldMap

func (*Snippet) ConvertToShellScript added in v0.2.3

func (snippet *Snippet) ConvertToShellScript() string

func (*Snippet) Describe

func (snippet *Snippet) Describe()

func (*Snippet) Execute

func (snippet *Snippet) Execute(options ...interface{}) error

func (*Snippet) Export

func (snippet *Snippet) Export(outputPath string, fileType string) error

func (*Snippet) GetFilePath

func (snippet *Snippet) GetFilePath() string

func (*Snippet) ParseStepRangeToIdx

func (snippet *Snippet) ParseStepRangeToIdx(stepRange string) (int, int, error)

func (*Snippet) Save

func (snippet *Snippet) Save(snippetsDir string) error

type SnippetsMeta

type SnippetsMeta struct {
	Snippets    []*jsonSnippet `json:"snippets"`
	IsMetaDirty bool           `json:"is_meta_dirty"`
	// contains filtered or unexported fields
}

func (*SnippetsMeta) DeleteSnippet

func (sm *SnippetsMeta) DeleteSnippet(title string) error

func (*SnippetsMeta) FindSnippet

func (sm *SnippetsMeta) FindSnippet(title string) (*Snippet, error)

func (*SnippetsMeta) GetSnippetTitles

func (sm *SnippetsMeta) GetSnippetTitles() []string

func (*SnippetsMeta) Save

func (sm *SnippetsMeta) Save() error

func (*SnippetsMeta) SaveNewSnippet

func (sm *SnippetsMeta) SaveNewSnippet(snippet *Snippet) error

Save new snippet into snippetsDir and update snippets meta file

func (*SnippetsMeta) SetFileLoc added in v0.2.4

func (sm *SnippetsMeta) SetFileLoc(fileLoc string)

func (*SnippetsMeta) SetSnippetsDir added in v0.2.4

func (sm *SnippetsMeta) SetSnippetsDir(path string)

func (*SnippetsMeta) SyncWithSnippets added in v0.2.4

func (sm *SnippetsMeta) SyncWithSnippets() error

type StepInfo

type StepInfo struct {
	Command     string `json:"command"`
	Description string `json:"description,omitempty"`
}

func NewStepInfo

func NewStepInfo(command string) *StepInfo

func (*StepInfo) AskQuestion

func (step *StepInfo) AskQuestion(options ...interface{}) error

func (*StepInfo) ConvertToShellScript added in v0.2.3

func (step *StepInfo) ConvertToShellScript(templates *TemplateFieldMap) string

func (*StepInfo) Execute

func (step *StepInfo) Execute(templates *TemplateFieldMap, options ...interface{}) error

TODO: add concurrent execution valid options include 'useDefaultVal' indicated by the --use-default flag

type TemplateField

type TemplateField struct {
	FieldName string
	Value     string
	Asked     bool
}

func (*TemplateField) AskQuestion

func (tf *TemplateField) AskQuestion(options ...interface{}) error

type TemplateFieldMap

type TemplateFieldMap map[string]*TemplateField // map from field name to template field object

func ParseTemplateFieldsMap

func ParseTemplateFieldsMap(c string) TemplateFieldMap

func (TemplateFieldMap) AddTemplateFieldIfNotExist

func (tfMap TemplateFieldMap) AddTemplateFieldIfNotExist(t *TemplateField)

type ZshCmdParser

type ZshCmdParser struct{}

func (ZshCmdParser) Parse

func (z ZshCmdParser) Parse(line string) string

Jump to

Keyboard shortcuts

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