cmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeAddedNotStaged added not staged
	CodeAddedNotStaged = " A"
	// CodeModifiedNotStaged modified not staged
	CodeModifiedNotStaged = " M"
	// CodeDeletedNotStaged deleted not staged
	CodeDeletedNotStaged = " D"
	// CodeRenamedNotStaged renamed in work tree not staged
	// not common, `git rename` will automatically stage the changes
	CodeRenamedNotStaged = " R"
	// CodeCopiedNotStaged copied in work tree not staged
	// not common, TODO: verify usage
	CodeCopiedNotStaged = " C"
	// CodeUntracked untracked
	CodeUntracked = "??"
	// PathSepArrow path separator if file is moved or copied
	PathSepArrow = "->"
)
View Source
const (
	// RequiredType error msg of missing type
	RequiredType = "commit type is required"
	// RequiredDesc error msg of missing description
	RequiredDesc = "commit description is required"
	// InvalidType error msg of invalid type
	InvalidType = "commit type is invalid"
	// InvalidScope error msg of invalid scope
	InvalidScope = "commit scope is invalid"
	// InvalidDesc error msg of invalid description
	InvalidDesc = "commit description is invalid"
	// InvalidBrkChnFTSep error msg of invalid breaking change footer separator
	InvalidBrkChnFTSep = "breaking change footer separator is invalid"
	// RequiredBrkChnFTDesc error msg of missing breaking footer description
	RequiredBrkChnFTDesc = "breaking change footer description is required"

	// InvalidFooter error msg of invalid footer
	InvalidFooter = "commit footer is invalid"
	// InvalidFooterToken error msg of invalid footer
	InvalidFooterToken = "commit footer token is invalid"
	// FTokenBrkChange special footer token
	FTokenBrkChange = "BREAKING CHANGE"
	// FTokenBrkChangeAlias FTokenBrkChange alias
	FTokenBrkChangeAlias = "BREAKING-CHANGE"
	// FSepColonSpace footer separator
	FSepColonSpace = ": "
	// FSepSpaceSharp footer separator
	FSepSpaceSharp = " #"
)
View Source
const CommitMsgTmpl = `` /* 178-byte string literal not displayed */

CommitMsgTmpl template for building commit message

View Source
const GitExec = "git"

GitExec git executable name

View Source
const VersionTmpl = `
{{- .Name}} {{.Version}}
`

VersionTmpl version template for --version output

Variables

View Source
var FootersQuestions = []*survey.Question{
	{
		Name: "footers",
		Prompt: &survey.Multiline{
			Message: "Enter optional footers:",
		},
	},
}

FootersQuestions ask footers input separately to handle custom parse logic

View Source
var PresetCommitTypes = []string{"fix", "feat", "build", "chore", "ci", "docs", "perf", "refactor", "style", "test"}

PresetCommitTypes conventional commits suggested types

UnstagedShortCodes git status --short output XY code of not staged files

Functions

func ContainsNewline

func ContainsNewline(s string) bool

ContainsNewline check if string contains newline chars

func ContainsWhiteSpace

func ContainsWhiteSpace(s string) bool

ContainsWhiteSpace check if string contains whitesapces

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func GitAdd added in v0.1.1

func GitAdd(fp string)

GitAdd exec `git add <filepath>`

func GitAddAll added in v0.1.1

func GitAddAll()

GitAddAll exec `git add .`

func GitCommit

func GitCommit(msg string)

GitCommit exec `git commit -m`

func GitRm added in v0.1.1

func GitRm(fp string)

GitRm exec `git rm` to stage changes of a deleted file

func IsBrkChnFooter

func IsBrkChnFooter(token string) bool

IsBrkChnFooter check if token is breaking change footer token

func MatchFooters added in v0.1.3

func MatchFooters(str string) []string

MatchFooters takes raw footers input string and return string slice of found footers. Match <token + sep>, find indices and take values in between Caveats: "BREAKING CHANGE #" is not matched, for " #" is not valid separator for breaking change, instead, "CHANGE #" is matched

func ParseFooter

func ParseFooter(f string) (token, sep, val string)

ParseFooter return components of a commit msg footer if seperable by ": " or " #" @param f footer without no newlines @return token "" if separated wrongly @return sep "" if separated wrongly @return val "" if separated wrongly

func TrimFooter added in v0.1.3

func TrimFooter(s string) string

TrimFooter separator space should not be trimed if no footer value Whitespace trimmed value may contains leading "#" or trailing ":", treat it as intention to mean a separator, add the space back

Types

type CommitFooters added in v0.1.3

type CommitFooters struct {
	Footers []string `survey:"footers"`
}

CommitFooters helper struct for separate survey with custom Setter

func (*CommitFooters) WriteAnswer added in v0.1.3

func (ft *CommitFooters) WriteAnswer(name string, value interface{}) error

WriteAnswer implements Settable interface of CommitMsg for survey assign string input to parsed footer slice

type CommitMsg

type CommitMsg struct {
	Type         string   `survey:"type"`        // required, preset or config values only
	Scope        string   `survey:"scope"`       // optional
	HasBrkChange bool     `survey:"breaking"`    // optional, default false
	Description  string   `survey:"description"` // required, no line break
	Body         string   `survey:"body"`        // optional, allow line breaks
	Footers      []string `survey:"footers"`     // optional, allow multiple lines
}

CommitMsg properties

func (*CommitMsg) Commit added in v0.1.1

func (cm *CommitMsg) Commit()

Commit validate and git commit the CommitMsg

func (*CommitMsg) Prompt added in v0.2.0

func (cm *CommitMsg) Prompt()

Prompt use interactive prompts to build the commit message

func (*CommitMsg) ToString

func (cm *CommitMsg) ToString() string

ToString format commit msg as conventional commits spec v1.0.0

func (*CommitMsg) Validate

func (cm *CommitMsg) Validate() (bool, string)

Validate commit msg elements @return valid {bool} @return msg {string} error msg

Jump to

Keyboard shortcuts

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