package cmd import ( "fmt" "os" "github.com/Pingu-Studio/MaidnCLI/internal/github" "github.com/Pingu-Studio/MaidnCLI/internal/utils" "github.com/spf13/cobra" ) var orgName, manifestsRepoName, fluxRepoName string var repoCmd = &cobra.Command{ Use: "repo", Short: "Manage CI/CD repositories.", } var initCmd = &cobra.Command{ Use: "init", Short: "Initializes the manifests and flux repositories with the required structure.", Run: runInitRepo, } func init() { rootCmd.AddCommand(repoCmd) repoCmd.AddCommand(initCmd) 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") } func runInitRepo(cmd *cobra.Command, args []string) { fmt.Println("[INFO] Checking dependencies (git and gh)...") if !utils.CommandExists("git") || !utils.CommandExists("gh") { fmt.Println("[ERROR] 'git' and 'gh' must be installed and in your PATH.") os.Exit(1) } fmt.Println("[INFO] Checking GitHub authentication...") if err := utils.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.") repoManager := github.NewRepoManager(orgName, manifestsRepoName, fluxRepoName) repoManager.InitializeManifestsRepo() repoManager.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) }