package cmd import ( "fmt" "github.com/Pingu-Studio/MaidnCLI/internal/bootstrap" "github.com/Pingu-Studio/MaidnCLI/internal/config" "github.com/spf13/cobra" ) var freshConfigPath, freshOrganization, onboardConfigPath, onboardFrom string var onboardAppName, onboardAppRepoURL, onboardImageRepository, onboardBuildStrategy string var freshCreateOrganization, freshEnableDelivery, freshYes bool var freshMode string var loadFreshConfig = config.Load var loadAppOnboardConfig = config.LoadRaw var runFreshOrganization = bootstrap.RunFreshOrganization var resolveAppOnboarding = config.ResolveAppOnboarding var onboardApp = bootstrap.OnboardApp var bootstrapInitCmd = &cobra.Command{ Use: "init", Short: "Create and lock a fresh Forgejo organization bootstrap workspace.", RunE: runBootstrapInit, } var appCmd = &cobra.Command{ Use: "app", Short: "Manage application delivery scaffolding.", } var appOnboardCmd = &cobra.Command{ Use: "onboard", Short: "Validate an application checkout and add its source-owned delivery contract.", RunE: runAppOnboard, } func init() { bootstrapCmd.AddCommand(bootstrapInitCmd) bootstrapInitCmd.Flags().StringVar(&freshConfigPath, "config", "", "Path to private bootstrap config YAML") bootstrapInitCmd.Flags().StringVar(&freshOrganization, "organization", "", "New Forgejo organization name") bootstrapInitCmd.Flags().BoolVar(&freshCreateOrganization, "create-organization", false, "Create the Forgejo organization when absent") bootstrapInitCmd.Flags().BoolVar(&freshEnableDelivery, "enable-delivery", false, "Deprecated: init always initializes the shared delivery platform") bootstrapInitCmd.Flags().StringVar(&freshMode, "mode", string(bootstrap.Reconcile), "Lifecycle mode: reconcile or rebuild") bootstrapInitCmd.Flags().BoolVar(&freshYes, "yes", false, "Confirm destructive rebuild") _ = bootstrapInitCmd.MarkFlagRequired("config") _ = bootstrapInitCmd.MarkFlagRequired("organization") rootCmd.AddCommand(appCmd) appCmd.AddCommand(appOnboardCmd) appOnboardCmd.Flags().StringVar(&onboardConfigPath, "config", "", "Path to private bootstrap config YAML") appOnboardCmd.Flags().StringVar(&onboardFrom, "from", "", "Clean application checkout to scaffold") appOnboardCmd.Flags().StringVar(&onboardAppName, "app-name", "", "Application name override") appOnboardCmd.Flags().StringVar(&onboardAppRepoURL, "app-repo-url", "", "Application repository URL override") appOnboardCmd.Flags().StringVar(&onboardImageRepository, "image-repository", "", "OCI image repository override") appOnboardCmd.Flags().StringVar(&onboardBuildStrategy, "build-strategy", "", "Build strategy override: static or runtime") _ = appOnboardCmd.MarkFlagRequired("config") _ = appOnboardCmd.MarkFlagRequired("from") } func runBootstrapInit(cmd *cobra.Command, _ []string) error { cfg, err := loadFreshConfig(freshConfigPath) if err != nil { return err } plan, err := runFreshOrganization(cfg, bootstrap.FreshOrganizationOptions{Organization: freshOrganization, CreateOrganization: freshCreateOrganization, EnableDelivery: freshEnableDelivery, Mode: bootstrap.Mode(freshMode), ConfirmRebuild: freshYes}) if err != nil { return err } for _, phase := range plan.Phases { fmt.Fprintf(cmd.OutOrStdout(), "[PLAN] %s\n", phase) } return nil } func runAppOnboard(_ *cobra.Command, _ []string) error { cfg, err := loadAppOnboardConfig(onboardConfigPath) if err != nil { return err } if onboardAppName != "" { cfg.Delivery.AppName = onboardAppName } if onboardAppRepoURL != "" { cfg.Delivery.AppRepoURL = onboardAppRepoURL } if onboardImageRepository != "" { cfg.Delivery.ImageRepository = onboardImageRepository } if onboardBuildStrategy != "" { cfg.Delivery.BuildStrategy = onboardBuildStrategy } cfg, err = resolveAppOnboarding(cfg) if err != nil { return err } return onboardApp(cfg, onboardFrom) }