cmd

package
v0.5.1-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommitCmd = &cobra.Command{
	Use:   "commit",
	Short: "Interactively commit using prompts",
	Long:  `Do the commit. This command is disabled when you are using commit hooks`,
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("commit called")
		log.Debug(commitMsg)
		spin := ui.NewSpinner()
		spin.Run()
		defer func() { spin.Stop() }()
		existentHookFiles, err := pkg.HookFilesExistent()
		if err != nil {
			log.Fatalf("Error checking if hook files existent")
		}
		if len(existentHookFiles) > 0 {
			log.Infof("There are hook files existent for %s", existentHookFiles)
			log.Infof("Please use git commit command or remove the hooks with %s hooks rm", pkg.ProgramName)
			spin.Stop()
			return
		}
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("get current config issue, %s", err)
		}
		gitmojis := pkg.GetGitmojis(config)
		initialCommitValues := pkg.BuildInitialCommitValues(
			_type,
			scope,
			desc,
			body,
			commitMsg,
			gitmojis.Gitmojis,
		)
		spin.Stop()
		commitValues := ui.CommitPrompt(config, gitmojis.Gitmojis, initialCommitValues, isBreaking)
		log.Debugf("complete title: %s", commitValues.Title)
		if isDryRun {
			log.Infof("The commit title: %s", commitValues.Title)
			log.Infof("The commit body: %s", commitValues.Body)
		} else {
			pkg.ExecuteCommit(commitValues.Title, commitValues.Body, config)
		}
	},
}

CommitCmd represents the commit command

View Source
var ConfigCmd = &cobra.Command{
	Use:   "config",
	Short: fmt.Sprintf("Setup %s preferences.", pkg.ProgramName),
	Long: `Configure the cli.
			There are default options available which are overwritten
			by the local configuration file or a global configuration file within your OS config folder (use the info command to get the information where it is stored)`,
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("config called")
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("get current config issue, %s", err)
		}
		autoAdd := runConfigConfirmationPrompt("Enable automatic 'git add .'", config.AutoAdd)
		autoSign := runConfigConfirmationPrompt("Automatically sign commits (add '-S' flag)", config.AutoSign)
		emojiFormat := runEmojiSelectionPrompt("Select how emojis should be used in commits. For a comparison please visit https://gitmoji.dev/specification")
		scopePrompt := runConfigConfirmationPrompt("Enable scope prompt", config.ScopePrompt)
		bodyPrompt := runConfigConfirmationPrompt("Enable body prompt", config.BodyPrompt)
		useDefaultGitMessages := runConfigConfirmationPrompt("Use default git messages (merge, squash,..)", config.UseDefaultGitMessages)
		debug := runConfigConfirmationPrompt("debug mode", config.Debug)
		capitalizeTitle := runConfigConfirmationPrompt("Capitalize title", config.CapitalizeTitle)
		gitmojisApiUrl := runGitmojiUrlInputPrompt("Set gitmojis api url", "https://gitmoji.dev/api/gitmojis")
		config = pkg.Config{
			AutoAdd:               autoAdd,
			AutoSign:              autoSign,
			EmojiFormat:           emojiFormat,
			ScopePrompt:           scopePrompt,
			CapitalizeTitle:       capitalizeTitle,
			GitmojisUrl:           gitmojisApiUrl,
			BodyPrompt:            bodyPrompt,
			UseDefaultGitMessages: useDefaultGitMessages,
			Debug:                 debug,
		}
		pkg.UpdateConfig(config, isConfigGlobal)
	},
}
View Source
var GlamourTheme = ansi.StyleConfig{
	Document: ansi.StyleBlock{
		StylePrimitive: ansi.StylePrimitive{
			BlockPrefix: "\n",
			BlockSuffix: "\n",
		},
		Margin: uintPtr(margin),
	},
	Heading: ansi.StyleBlock{
		StylePrimitive: ansi.StylePrimitive{
			BlockSuffix: "\n",
			Color:       stringPtr("99"),
			Bold:        boolPtr(true),
		},
	},
	Item:     ansi.StylePrimitive{Prefix: "· "},
	Emph:     ansi.StylePrimitive{Color: stringPtr(brightBlack)},
	Strong:   ansi.StylePrimitive{Bold: boolPtr(true)},
	Link:     ansi.StylePrimitive{Color: stringPtr("42"), Underline: boolPtr(true)},
	LinkText: ansi.StylePrimitive{Color: stringPtr("207")},
	Code:     ansi.StyleBlock{StylePrimitive: ansi.StylePrimitive{Color: stringPtr("204")}},
}
View Source
var HooksCmd = &cobra.Command{
	Use:   "hooks",
	Short: fmt.Sprintf("Manage %s commit hooks", pkg.ProgramName),
	Long:  `Manage git hooks for the cli`,
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("get current config issue, %s", err)
		}
		log.Debug("hooks called")
		log.Debugf("run: %v", args)
		if hook {
			if len(args) == 0 {
				log.Fatalf("len(args) must not be 0 when using pre-commit-message hook https://git-scm.com/docs/githooks#_prepare_commit_msg")
			}
			hookCommitMessageFile := args[0]
			log.Debugf("hook message file %s", hookCommitMessageFile)
			if len(args) > 1 {
				hookCommitMsgSource := args[1]
				log.Debugf("hook message source %s", hookCommitMsgSource)
				if config.UseDefaultGitMessages {
					log.Debugf("Default git messages used")
					switch hookCommitMsgSource {
					case string(pkg.MERGE):
						log.Infof("Merge commit, using default git message")
						return
					case string(pkg.SQUASH):
						log.Infof("Squash commit, using default git message")
						return
					}
				}
			}

			hookCommit(hookCommitMessageFile, config)
		} else {
			err := cmd.Help()
			if err != nil {
				log.Fatalf("issue with the help command %s", err)
				return
			}
		}
	},
}
View Source
var HooksInitCmd = &cobra.Command{
	Use:   "init",
	Short: fmt.Sprintf("initialize git hooks for %s", pkg.ProgramName),
	Long:  `Install the commit hooks into the local .git/hooks/ directory.`,
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("hooks init called")
		spin := ui.NewSpinner()
		spin.Run()
		defer func() {
			spin.Stop()
		}()
		err := pkg.CreateAllHookFiles()
		if err != nil {
			log.Error(err)
			return
		}
		log.Info("The hook is now initialized")
		log.Infof("happy coding %s", "🚀")
	},
}
View Source
var HooksRemoveCmd = &cobra.Command{
	Use:   "rm",
	Short: fmt.Sprintf("remove git hooks for %s", pkg.ProgramName),
	Long:  `Delete the commit hooks which are created by the cli`,
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("hooks rm called")
		spin := ui.NewSpinner()
		spin.Run()
		defer func() { spin.Stop() }()
		err := pkg.RemoveAllHookFiles()
		if err != nil {
			log.Error(err)
			return
		}
		log.Info("The hook is now removed")
		log.Infof("happy coding %s", "🚀")
	},
}
View Source
var InfoCmd = &cobra.Command{
	Use:   "info",
	Short: "Get some relevant information",
	Long:  `Get some information like config or cache directory on your OS where the cli is writing configuration or cache.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("error while getting config %s", err)
		}
		globalConfigDir, _ := utils.GetGlobalConfigDir(pkg.ProgramName)
		cacheDir, _ := utils.GetCacheDir(pkg.ProgramName)
		log.Debug("info called")
		log.Infof("program name: %s", pkg.ProgramName)
		log.Infof("version: %s", pkg.Version)
		log.Info("It is possible to store the configuration within the repository or globally")
		log.Infof("The global config path: %s", globalConfigDir)
		log.Infof("The gitmoji information is queried from the internet at the gitmoji defined in the config %s", config.GitmojisUrl)
		log.Info("and cached")
		log.Infof("Gitmoji cache dir: %s", cacheDir)
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all the available gitmojis",
	Long:  fmt.Sprintf(`The list is queried from the api %s.`, pkg.DefaultGitmojiApiUrl),
}
View Source
var ListCommitTypesCmd = &cobra.Command{
	Use:   "commit-types",
	Short: "List all the available commit types",
	Long:  "The list from conventional commits is used",
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("list commit-types called")
		spin := ui.NewSpinner()
		spin.Run()
		defer func() { spin.Stop() }()
		defaultTypes := pkg.DefaultCommitTypes()
		spin.Stop()
		listSettings := ui.ListSettings{Title: "Commit types", IsShowStatusBar: true, IsFilteringEnabled: true}
		selectedDefaultType := ui.ListRun(listSettings, defaultTypes)
		log.Debugf("selected %s", selectedDefaultType)
	},
}
View Source
var ListGitmojisCmd = &cobra.Command{
	Use:   "gitmojis",
	Short: "List all the available gitmojis",
	Long:  fmt.Sprintf(`The list is queried from the api %s.`, pkg.DefaultGitmojiApiUrl),
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("list gitmojis called")
		spin := ui.NewSpinner()
		spin.Run()
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("get current config issue, %s", err)
		}
		gitmojis := pkg.GetGitmojis(config)
		spin.Stop()
		listSettings := ui.ListSettings{Title: "Gitmojis", IsShowStatusBar: true, IsFilteringEnabled: true}
		selectedGitmoji := ui.ListRun(listSettings, gitmojis.Gitmojis)
		log.Debugf("selected %s", selectedGitmoji)
	},
}
View Source
var RootCmd = &cobra.Command{
	Use: pkg.ProgramName,
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Short: "Cli to help managing gitmoji commit messages",
	Long:  fmt.Sprintf(`See %s for more information about Gitmoji`, pkg.DefaultGitmojiUrl),
}
View Source
var UpdateGitmojisCmd = &cobra.Command{
	Use: "gitmojis",
	PreRun: func(cmd *cobra.Command, args []string) {
		programNameFigure()
	},
	Short: fmt.Sprintf("update the local gitmoji database %s", pkg.ProgramName),
	Long:  fmt.Sprintf(`Update the gitmojis local cache from %s.`, pkg.DefaultGitmojiApiUrl),
	Run: func(cmd *cobra.Command, args []string) {
		log.Debug("update gitmojis called")
		spin := ui.NewSpinner()
		spin.Run()
		defer func() {
			spin.Stop()
		}()
		config, err := pkg.GetCurrentConfig()
		if err != nil {
			log.Fatalf("get current config issue, %s", err)
		}
		gitmojis := pkg.UpdateGitmojis(config)
		pkg.CacheGitmojis(gitmojis)
		log.Info("done updating the cached gitmojis file")
	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

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