package main import ( _ "embed" "fmt" "os" "github.com/spf13/cobra" ) var orgName, manifestsRepoName, fluxRepoName string //go:embed templates/manifests.md.tmpl var manifestsReadmeTmpl string //go:embed templates/flux.md.tmpl var fluxReadmeTmpl string func main() { var rootCmd = &cobra.Command{ Use: "cicd-tool", Short: "A CLI tool to manage CI/CD setup for applications.", } var repoCmd = &cobra.Command{ Use: "repo", Short: "Manage CI/CD repositories.", } var vaultCmd = &cobra.Command{ Use: "vault", Short: "Manage Vault secrets for CI/CD.", } var initCmd = &cobra.Command{ Use: "init", Short: "Initializes the manifests and flux repositories with the required structure.", Run: runInitRepo, } var createSecretCmd = &cobra.Command{ Use: "create-docker-secret", Short: "Creates a Docker registry secret in Vault for GHCR authentication.", Run: runCreateDockerSecret, } // Define command flags for repo init initCmd.Flags().StringVar(&orgName, "org", "", "The GitHub organization (e.g., Free-Maidn)") initCmd.Flags().StringVar(&manifestsRepoName, "manifests-repo", "cicd-deployment-manifests", "The name of the manifests repository") initCmd.Flags().StringVar(&fluxRepoName, "flux-repo", "", "The name of the flux repository") initCmd.MarkFlagRequired("org") initCmd.MarkFlagRequired("flux-repo") // Add commands to their parent commands repoCmd.AddCommand(initCmd) vaultCmd.AddCommand(createSecretCmd) rootCmd.AddCommand(repoCmd) rootCmd.AddCommand(vaultCmd) if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } func runInitRepo(cmd *cobra.Command, args []string) { // Check system dependencies fmt.Println("[INFO] Checking dependencies (git and gh)...") if !commandExists("git") || !commandExists("gh") { fmt.Println("[ERROR] 'git' and 'gh' must be installed and in your PATH.") os.Exit(1) } // Verify GitHub authentication fmt.Println("[INFO] Checking GitHub authentication...") if err := runCommandQuiet("gh", "auth", "status"); err != nil { fmt.Println("[ERROR] You are not logged into the GitHub CLI. Please run 'gh auth login'.") os.Exit(1) } fmt.Println("[SUCCESS] Dependencies and authentication are OK.") // Initialize both repositories initializeManifestsRepo() initializeFluxRepo() fmt.Println("\nšŸŽ‰ Onboarding complete! šŸŽ‰") fmt.Printf("āœ… Manifests repository: https://github.com/%s/%s\n", orgName, manifestsRepoName) fmt.Printf("āœ… Flux repository: https://github.com/%s/%s\n", orgName, fluxRepoName) } func runCreateDockerSecret(cmd *cobra.Command, args []string) { if err := createAndStoreSecrets(); err != nil { fmt.Printf("[ERROR] Failed to create Docker registry secret: %v\n", err) os.Exit(1) } fmt.Println("[SUCCESS] Docker registry secret created successfully in Vault!") }