diff --git a/packages/kn-plugin-workflow/pkg/command/deploy.go b/packages/kn-plugin-workflow/pkg/command/deploy.go index 4a3098960b4..6db7f23f6ce 100644 --- a/packages/kn-plugin-workflow/pkg/command/deploy.go +++ b/packages/kn-plugin-workflow/pkg/command/deploy.go @@ -81,6 +81,11 @@ func NewDeployCommand() *cobra.Command { cmd.Flags().StringP("specs-dir", "p", "", "Specify a custom specs files directory") cmd.Flags().StringP("subflows-dir", "s", "", "Specify a custom subflows files directory") cmd.Flags().StringP("schemas-dir", "t", "", "Specify a custom schemas files directory") + cmd.Flags().BoolP("minify", "f", true, "Minify the OpenAPI specs files before deploying") + + if err := viper.BindPFlag("minify", cmd.Flags().Lookup("minify")); err != nil { + fmt.Println("❌ ERROR: failed to bind minify flag") + } cmd.SetHelpFunc(common.DefaultTemplatedHelp) @@ -159,6 +164,7 @@ func runDeployCmdConfig(cmd *cobra.Command) (cfg DeployUndeployCmdConfig, err er SpecsDir: viper.GetString("specs-dir"), SchemasDir: viper.GetString("schemas-dir"), SubflowsDir: viper.GetString("subflows-dir"), + Minify: viper.GetBool("minify"), } if len(cfg.SubflowsDir) == 0 { diff --git a/packages/kn-plugin-workflow/pkg/command/deploy_undeploy_common.go b/packages/kn-plugin-workflow/pkg/command/deploy_undeploy_common.go index fcb18d21adc..3519c8e99fc 100644 --- a/packages/kn-plugin-workflow/pkg/command/deploy_undeploy_common.go +++ b/packages/kn-plugin-workflow/pkg/command/deploy_undeploy_common.go @@ -50,6 +50,7 @@ type DeployUndeployCmdConfig struct { SpecsFilesPath map[string]string SubFlowsFilesPath []string DashboardsPath []string + Minify bool } func checkEnvironment(cfg *DeployUndeployCmdConfig) error { @@ -123,14 +124,26 @@ func generateManifests(cfg *DeployUndeployCmdConfig) error { supportFileExtensions := []string{metadata.JSONExtension, metadata.YAMLExtension, metadata.YMLExtension} fmt.Println("🔍 Looking for specs files...") - minifiedfiles, err := specs.NewMinifier(&specs.OpenApiMinifierOpts{ - SpecsDir: cfg.SpecsDir, - SubflowsDir: cfg.SubflowsDir, - }).Minify() - if err != nil { - return fmt.Errorf("❌ ERROR: failed to minify specs files: %w", err) + if cfg.Minify { + minifiedfiles, err := specs.NewMinifier(&specs.OpenApiMinifierOpts{ + SpecsDir: cfg.SpecsDir, + SubflowsDir: cfg.SubflowsDir, + }).Minify() + if err != nil { + return fmt.Errorf("❌ ERROR: failed to minify specs files: %w", err) + } + cfg.SpecsFilesPath = minifiedfiles + } else { + files, err = common.FindFilesWithExtensions(cfg.SpecsDir, supportFileExtensions) + if err != nil { + return fmt.Errorf("❌ ERROR: failed to get supportFiles directory: %w", err) + } + cfg.SpecsFilesPath = map[string]string{} + for _, file := range files { + cfg.SpecsFilesPath[file] = file + fmt.Printf(" - ✅ Specs file found: %s\n", file) + } } - cfg.SpecsFilesPath = minifiedfiles fmt.Println("🔍 Looking for schema files...") files, err = common.FindFilesWithExtensions(cfg.SchemasDir, supportFileExtensions)