Skip to content

Commit

Permalink
docs: improve documentation and clarity across multiple files
Browse files Browse the repository at this point in the history
- Update flag descriptions for better clarity in `commit.go`
- Expand the `Long` description in `completion.go` to include detailed instructions for loading shell completions
- Improve comments and error messages in `config.go` and `hepler.go` for better readability and clarity

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Mar 5, 2025
1 parent 5c06988 commit 4d02d6e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
22 changes: 11 additions & 11 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ var (
)

func init() {
commitCmd.PersistentFlags().StringP("file", "f", "", "output file for commit message")
commitCmd.PersistentFlags().StringP("file", "f", "", "specify output file for commit message")
commitCmd.PersistentFlags().BoolVar(&preview, "preview", false, "preview commit message before committing")
commitCmd.PersistentFlags().IntVar(&diffUnified, "diff_unified", 3,
"generate diffs with <n> lines of context (default: 3)")
commitCmd.PersistentFlags().StringVar(&commitModel, "model", "gpt-4o", "OpenAI model to use for generation")
commitCmd.PersistentFlags().StringVar(&commitLang, "lang", "en", "output language for the commit message (default: English)")
commitCmd.PersistentFlags().StringVar(&commitModel, "model", "gpt-4o", "specify which OpenAI model to use for generation")
commitCmd.PersistentFlags().StringVar(&commitLang, "lang", "en", "set output language for the commit message (default: English)")
commitCmd.PersistentFlags().StringSliceVar(&excludeList, "exclude_list", []string{},
"files to exclude from git diff")
commitCmd.PersistentFlags().StringVar(&httpsProxy, "proxy", "", "HTTP proxy URL")
commitCmd.PersistentFlags().StringVar(&socksProxy, "socks", "", "SOCKS proxy URL")
commitCmd.PersistentFlags().StringVar(&templateFile, "template_file", "", "template file for commit message format")
commitCmd.PersistentFlags().StringVar(&templateString, "template_string", "", "inline template string for commit message format")
commitCmd.PersistentFlags().StringSliceVar(&templateVars, "template_vars", []string{}, "custom variables for templates")
commitCmd.PersistentFlags().StringVar(&templateVarsFile, "template_vars_file", "", "file containing template variables")
"specify files to exclude from git diff")
commitCmd.PersistentFlags().StringVar(&httpsProxy, "proxy", "", "set HTTP proxy URL")
commitCmd.PersistentFlags().StringVar(&socksProxy, "socks", "", "set SOCKS proxy URL")
commitCmd.PersistentFlags().StringVar(&templateFile, "template_file", "", "provide template file for commit message format")
commitCmd.PersistentFlags().StringVar(&templateString, "template_string", "", "provide inline template string for commit message format")
commitCmd.PersistentFlags().StringSliceVar(&templateVars, "template_vars", []string{}, "define custom variables for templates")
commitCmd.PersistentFlags().StringVar(&templateVarsFile, "template_vars_file", "", "specify file containing template variables")
commitCmd.PersistentFlags().BoolVar(&commitAmend, "amend", false,
"amend the previous commit instead of creating a new one")
commitCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", defaultTimeout, "API request timeout duration")
commitCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", defaultTimeout, "set API request timeout duration")
commitCmd.PersistentFlags().BoolVar(&promptOnly, "prompt_only", false,
"display the prompt without sending to OpenAI")
commitCmd.PersistentFlags().BoolVar(&noConfirm, "no_confirm", false,
Expand Down
26 changes: 23 additions & 3 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,29 @@ import (
)

var CompletionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: "To load completions",
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: `Generate shell completion scripts for CodeGPT CLI.
To load completions:
Bash:
$ source <(codegpt completion bash)
# Or save it to a file and source it:
$ codegpt completion bash > ~/.codegpt-completion.bash
$ echo 'source ~/.codegpt-completion.bash' >> ~/.bashrc
Zsh:
$ source <(codegpt completion zsh)
# Or save it to a file in your $fpath:
$ codegpt completion zsh > "${fpath[1]}/_codegpt"
Fish:
$ codegpt completion fish > ~/.config/fish/completions/codegpt.fish
PowerShell:
PS> codegpt completion powershell > codegpt.ps1
PS> . ./codegpt.ps1`,
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Expand Down
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
)

// configCmd represents the command for custom configuration,
// including openai.api_key and openai.model and etc...
// including settings like openai.api_key, openai.model, and others.
var configCmd = &cobra.Command{
Use: "config",
Short: "custom config (openai.api_key, openai.model ...)",
Short: "Customize configuration settings (API key, model selection, etc.)",
}
13 changes: 6 additions & 7 deletions cmd/hepler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (
"github.com/appleboy/CodeGPT/provider/openai"
"github.com/appleboy/CodeGPT/util"
"github.com/appleboy/com/file"

"github.com/spf13/viper"
)

func check() error {
// Check if the Git command is available on the system's PATH
if !util.IsCommandAvailable("git") {
return errors.New("git command not found on your system's PATH. Please install Git and try again")
return errors.New("git command not found in your system's PATH. Please install Git and try again")
}

// Update Viper configuration values based on the CLI flags
// Apply configuration values from CLI flags to Viper
if diffUnified != 3 {
viper.Set("git.diff_unified", diffUnified)
}
Expand Down Expand Up @@ -55,17 +54,17 @@ func check() error {
viper.Set("git.template_string", templateString)
}

// Check if the template file specified in the configuration exists
// Verify template file existence
templateFile := viper.GetString("git.template_file")
if templateFile != "" && !file.IsFile(templateFile) {
return fmt.Errorf("template file not found: %s", templateFile)
return fmt.Errorf("template file not found at: %s", templateFile)
}

if templateVarsFile != "" && !file.IsFile(templateVarsFile) {
return fmt.Errorf("template variables file not found: %s", templateVarsFile)
return fmt.Errorf("template variables file not found at: %s", templateVarsFile)
}

// load custom prompt
// Load custom prompts from configured directory
promptFolder := viper.GetString("prompt.folder")
if promptFolder != "" {
if err := util.LoadTemplatesFromDir(promptFolder); err != nil {
Expand Down

0 comments on commit 4d02d6e

Please sign in to comment.