cmd

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 14 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

Variables

View Source
var CommitMsgQuestions = []*survey.Question{
	{
		Name: "type",
		Prompt: &survey.Select{
			Message: "Choose commit type:",
			Options: PresetCommitTypes,
			Default: PresetCommitTypes[0],
		},
	},
	{
		Name: "scope",
		Prompt: &survey.Input{
			Message: "Enter commit scope:",
		},
		Transform: survey.ComposeTransformers(

			survey.TransformString(strings.ToLower),
			survey.TransformString(strings.TrimSpace),
		),
	},
	{
		Name: "breaking",
		Prompt: &survey.Confirm{
			Message: "Includes breaking changes?",
			Default: false,
		},
	},
	{
		Name: "description",
		Prompt: &survey.Input{
			Message: fmt.Sprintln("Enter commit description:"),
		},
		Validate:  survey.Required,
		Transform: survey.TransformString(strings.TrimSpace),
	},
	{
		Name: "body",
		Prompt: &survey.Multiline{
			Message: fmt.Sprintln("Enter optional detail description:"),
		},
	},
}

CommitMsgQuestions build CommitMsg struct for interactive commit mode

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

Types

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