feat: initial commit of Git Automation CLI

- Add comprehensive Git workflow automation tools
- Include branch management utilities
- Add commit helpers with conventional commit support
- Implement GitHub integration for PR management
- Add configuration management system
- Include comprehensive test coverage
- Add professional documentation and examples
This commit is contained in:
Dev
2025-09-11 17:02:12 +03:00
commit 15bbfdcda2
27 changed files with 5727 additions and 0 deletions

107
internal/cmd/config.go Normal file
View File

@@ -0,0 +1,107 @@
package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/iwasforcedtobehere/git-automation-cli/internal/config"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage configuration settings",
Long: `View and modify configuration settings for gitauto.
Settings can be stored in the configuration file or as environment variables.`,
}
var configGetCmd = &cobra.Command{
Use: "get [key]",
Short: "Get a configuration value",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
// Show all config values
fmt.Fprintf(cmd.OutOrStdout(), "Configuration file: %s\n\n", config.GetConfigFile())
fmt.Fprintf(cmd.OutOrStdout(), "Default Remote: %s\n", config.GlobalConfig.DefaultRemote)
fmt.Fprintf(cmd.OutOrStdout(), "Default Branch: %s\n", config.GlobalConfig.DefaultBranch)
fmt.Fprintf(cmd.OutOrStdout(), "GitHub URL: %s\n", config.GlobalConfig.GitHubURL)
fmt.Fprintf(cmd.OutOrStdout(), "Auto Cleanup: %t\n", config.GlobalConfig.AutoCleanup)
fmt.Fprintf(cmd.OutOrStdout(), "Confirm Destructive: %t\n", config.GlobalConfig.ConfirmDestructive)
fmt.Fprintf(cmd.OutOrStdout(), "Dry Run: %t\n", config.GlobalConfig.DryRun)
fmt.Fprintf(cmd.OutOrStdout(), "Verbose: %t\n", config.GlobalConfig.Verbose)
fmt.Fprintf(cmd.OutOrStdout(), "Branch Prefix: %s\n", config.GlobalConfig.BranchPrefix)
fmt.Fprintf(cmd.OutOrStdout(), "Feature Prefix: %s\n", config.GlobalConfig.FeaturePrefix)
fmt.Fprintf(cmd.OutOrStdout(), "Hotfix Prefix: %s\n", config.GlobalConfig.HotfixPrefix)
if config.GlobalConfig.GitHubToken != "" {
fmt.Fprintf(cmd.OutOrStdout(), "GitHub Token: %s\n", maskToken(config.GlobalConfig.GitHubToken))
}
} else {
// Show specific config value
key := args[0]
value := config.Get(key)
if value == nil {
fmt.Fprintf(cmd.ErrOrStderr(), "Configuration key '%s' not found\n", key)
cmd.SilenceUsage = true
return fmt.Errorf("configuration key '%s' not found", key)
}
// Mask sensitive values
if strings.Contains(key, "token") || strings.Contains(key, "password") {
fmt.Fprintf(cmd.OutOrStdout(), "%s: %s\n", key, maskToken(fmt.Sprintf("%v", value)))
} else {
fmt.Fprintf(cmd.OutOrStdout(), "%s: %v\n", key, value)
}
}
return nil
},
}
var configSetCmd = &cobra.Command{
Use: "set [key] [value]",
Short: "Set a configuration value",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
key := args[0]
value := args[1]
config.Set(key, value)
if err := config.Save(); err != nil {
fmt.Fprintf(cmd.ErrOrStderr(), "Error saving configuration: %v\n", err)
return fmt.Errorf("error saving configuration: %v", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Set %s = %v\n", key, value)
return nil
},
}
var configInitCmd = &cobra.Command{
Use: "init",
Short: "Initialize configuration file",
RunE: func(cmd *cobra.Command, args []string) error {
if err := config.Save(); err != nil {
fmt.Fprintf(cmd.ErrOrStderr(), "Error creating configuration file: %v\n", err)
return fmt.Errorf("error creating configuration file: %v", err)
}
fmt.Fprintf(cmd.OutOrStdout(), "Configuration file created at: %s\n", config.GetConfigFile())
return nil
},
}
func maskToken(token string) string {
if len(token) <= 8 {
return strings.Repeat("*", len(token))
}
// For GitHub tokens, use a standard masking format
if strings.HasPrefix(token, "ghp_") {
return token[:4] + strings.Repeat("*", 28) + token[len(token)-4:]
}
// For other tokens, use the original logic
return token[:4] + strings.Repeat("*", len(token)-8) + token[len(token)-4:]
}
func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(configGetCmd)
configCmd.AddCommand(configSetCmd)
configCmd.AddCommand(configInitCmd)
}