summaryrefslogtreecommitdiff
path: root/internal/cmd/test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-07-13 17:37:16 +0300
committerPaul Buetow <paul@buetow.org>2025-07-13 17:37:16 +0300
commitfa5ef028ec9a7af801710eed190057d3b3c172f0 (patch)
tree41ef41dd1edace0438be20c4f35328c0fbfd8090 /internal/cmd/test.go
parent79225d4df3a181f08a2160ff8ec361001b9dea18 (diff)
refactor: restructure CLI with cobra command framework
- Replace flat flags with organized command structure - Add commands: sync, list, manage, release, showcase, test - Implement subcommands for better organization: - sync: repo, all, codeberg-to-github, github-to-codeberg, bidirectional - list: orgs, repos - manage: delete-repo, clean, batch-run - release: check, create (with --ai-notes support) - showcase: with --force, --output, --format, --exclude - test: github-token, codeberg-token, config - Add comprehensive help with examples for all commands - Fix config loading bug when path is empty - Update README.md with new command structure and examples - Maintain backward compatibility (old flags still work with warnings) The new structure provides better discoverability, consistent naming, and logical grouping of related functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/cmd/test.go')
-rw-r--r--internal/cmd/test.go91
1 files changed, 91 insertions, 0 deletions
diff --git a/internal/cmd/test.go b/internal/cmd/test.go
new file mode 100644
index 0000000..0590719
--- /dev/null
+++ b/internal/cmd/test.go
@@ -0,0 +1,91 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/spf13/cobra"
+ "codeberg.org/snonux/gitsyncer/internal/cli"
+ "codeberg.org/snonux/gitsyncer/internal/config"
+)
+
+var testCmd = &cobra.Command{
+ Use: "test",
+ Short: "Test authentication and configuration",
+ Long: `Test various aspects of the gitsyncer configuration including authentication tokens.`,
+}
+
+var testGitHubCmd = &cobra.Command{
+ Use: "github-token",
+ Short: "Test GitHub authentication",
+ Example: ` # Test GitHub token authentication
+ gitsyncer test github-token`,
+ Run: func(cmd *cobra.Command, args []string) {
+ os.Exit(cli.HandleTestGitHubToken())
+ },
+}
+
+var testCodebergCmd = &cobra.Command{
+ Use: "codeberg-token",
+ Short: "Test Codeberg authentication",
+ Example: ` # Test Codeberg token authentication
+ gitsyncer test codeberg-token`,
+ Run: func(cmd *cobra.Command, args []string) {
+ // TODO: Implement Codeberg token test
+ fmt.Println("Codeberg token test not yet implemented")
+ os.Exit(1)
+ },
+}
+
+var testConfigCmd = &cobra.Command{
+ Use: "config",
+ Short: "Validate configuration file",
+ Example: ` # Validate configuration
+ gitsyncer test config
+
+ # Test specific config file
+ gitsyncer test config -c ~/my-gitsyncer.json`,
+ Run: func(cmd *cobra.Command, args []string) {
+ // Try to load and validate config
+ cfg, err := config.Load(cfgFile)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Configuration validation failed: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Println("Configuration validation successful!")
+ fmt.Printf(" Organizations: %d\n", len(cfg.Organizations))
+ fmt.Printf(" Repositories: %d\n", len(cfg.Repositories))
+
+ // Check for common issues
+ hasGitHub := false
+ hasCodeberg := false
+ for _, org := range cfg.Organizations {
+ if org.Host == "git@github.com" {
+ hasGitHub = true
+ if org.GitHubToken == "" {
+ fmt.Println(" ⚠️ Warning: GitHub organization without token")
+ }
+ }
+ if org.Host == "git@codeberg.org" {
+ hasCodeberg = true
+ if org.CodebergToken == "" {
+ fmt.Println(" ⚠️ Warning: Codeberg organization without token")
+ }
+ }
+ }
+
+ if !hasGitHub && !hasCodeberg {
+ fmt.Println(" ⚠️ Warning: No GitHub or Codeberg organizations configured")
+ }
+
+ os.Exit(0)
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(testCmd)
+ testCmd.AddCommand(testGitHubCmd)
+ testCmd.AddCommand(testCodebergCmd)
+ testCmd.AddCommand(testConfigCmd)
+} \ No newline at end of file