github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow@v0.28.1-0.20240311201729-34c6856b157f/pkg/root/root.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package root 21 22 import ( 23 "fmt" 24 25 "github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/command/quarkus" 26 27 "github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/command" 28 "github.com/apache/incubator-kie-tools/packages/kn-plugin-workflow/pkg/common" 29 "github.com/ory/viper" 30 "github.com/spf13/cobra" 31 ) 32 33 type RootCmdConfig struct { 34 Name string 35 Version string 36 } 37 38 func NewRootCommand(cfg RootCmdConfig) *cobra.Command { 39 var cmd = &cobra.Command{ 40 Use: cfg.Name, 41 Short: "SonataFlow", 42 Long: ` 43 Manage SonataFlow projects 44 ========================== 45 46 Currently, SonataFlow targets use cases with a single Serverless Workflow main 47 file definition (i.e. workflow.sw.{json|yaml|yml}). 48 49 Additionally, you can define the configurable parameters of your application in the 50 "application.properties" file (inside the root project directory). 51 You can also store your spec files (i.e., Open API files) inside the "specs" folder, 52 schemas file inside "schemas" folder and also subflows inside "subflows" folder. 53 54 A SonataFlow project, as the following structure by default: 55 56 Workflow project root 57 /specs (optional) 58 /schemas (optional) 59 /subflows (optional) 60 workflow.sw.{json|yaml|yml} (mandatory) 61 62 `, 63 Aliases: []string{"kn-workflow"}, 64 } 65 66 viper.AutomaticEnv() // read in environment variables for WORKFLOW_<flag> 67 viper.SetEnvPrefix("workflow") // ensure that all have the prefix 68 69 cmd.Version = cfg.Version 70 cmd.SetVersionTemplate(`{{printf "%s\n" .Version}}`) 71 72 cmd.AddCommand(command.NewCreateCommand()) 73 cmd.AddCommand(command.NewRunCommand()) 74 cmd.AddCommand(command.NewDeployCommand()) 75 cmd.AddCommand(command.NewUndeployCommand()) 76 cmd.AddCommand(command.NewGenManifest()) 77 cmd.AddCommand(quarkus.NewQuarkusCommand()) 78 cmd.AddCommand(command.NewVersionCommand(cfg.Version)) 79 80 cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { 81 runRootHelp(cmd, args) 82 }) 83 84 return cmd 85 } 86 87 func runRootHelp(cmd *cobra.Command, args []string) { 88 tpl := common.GetTemplate(cmd, "root") 89 var data = struct { 90 Name string 91 }{ 92 Name: cmd.Root().Use, 93 } 94 95 if err := tpl.Execute(cmd.OutOrStdout(), data); err != nil { 96 fmt.Fprintf(cmd.ErrOrStderr(), "unable to display help text: %v", err) 97 } 98 }