github.com/projectriff/riff-cli@v0.0.5-0.20180301104501-5db7a3bd9fc1/cmd/utils/command_utils.go (about) 1 /* 2 * Copyright 2018 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package utils 18 19 import ( 20 "bytes" 21 "text/template" 22 ) 23 24 const ( 25 initResult = `generate the required Dockerfile and resource definitions using sensible defaults` 26 initDefinition = `Generate` 27 createResult = `create the required Dockerfile and resource definitions, and apply the resources, using sensible defaults` 28 createDefinition = `Create` 29 ) 30 31 const baseCommandDescription = `{{.Process}} the function based on the function source code specified as the filename, using the name 32 and version specified for the function image repository and tag. 33 34 For example, from a directory named 'square' containing a function 'square.js', you can simply type : 35 36 riff {{.Command}} node -f square 37 38 or 39 40 riff {{.Command}} node 41 42 to {{.Result}}.` 43 44 const baseJavaDescription = `{{.Process}} the function based on the function source code specified as the filename, using the artifact (jar file), 45 the function handler(classname), the name and version specified for the function image repository and tag. 46 47 For example, from a maven project directory named 'greeter', type: 48 49 riff {{.Command}} -i greetings -l java -a target/greeter-1.0.0.jar --handler=Greeter 50 51 to {{.Result}}.` 52 53 const baseShellDescription = `{{.Process}} the function based on the function script specified as the filename, using the name 54 and version specified for the function image repository and tag. 55 56 For example, from a directory named 'echo' containing a function 'echo.sh', you can simply type : 57 58 riff {{.Command}} -f echo 59 60 or 61 62 riff {{.Command}} 63 64 to {{.Result}}.` 65 66 const baseNodeDescription = `{{.Process}} the function based on the function source code specified as the filename, using the name 67 and version specified for the function image repository and tag. 68 69 For example, from a directory named 'square' containing a function 'square.js', you can simply type : 70 71 riff {{.Command}} -f square 72 73 or 74 75 riff {{.Command}} 76 77 to {{.Result}}.` 78 79 const basePythonDescription = `{{.Process}} the function based on the function source code specified as the filename, handler, 80 name, artifact and version specified for the function image repository and tag. 81 82 For example, type: 83 84 riff {{.Command}} -i words -l python --n uppercase --handler=process 85 86 to {{.Result}}.` 87 88 type LongVals struct { 89 Process string 90 Command string 91 Result string 92 } 93 94 func InitCmdLong() string { 95 return createCmdLong(baseCommandDescription, LongVals{Process: initDefinition, Command: "init", Result: initResult}) 96 } 97 98 func InitJavaCmdLong() string { 99 return createCmdLong(baseJavaDescription, LongVals{Process: initDefinition, Command: "init java", Result: initResult}) 100 } 101 102 func InitShellCmdLong() string { 103 return createCmdLong(baseShellDescription, LongVals{Process: initDefinition, Command: "init shell", Result: initResult}) 104 } 105 106 func InitNodeCmdLong() string { 107 return createCmdLong(baseNodeDescription, LongVals{Process: initDefinition, Command: "init node", Result: initResult}) 108 } 109 110 func InitPythonCmdLong() string { 111 return createCmdLong(basePythonDescription, LongVals{Process: initDefinition, Command: "init python", Result: initResult}) 112 } 113 114 func CreateCmdLong() string { 115 return createCmdLong(baseCommandDescription, LongVals{Process: createDefinition, Command: "create", Result: createResult}) 116 } 117 118 func CreateJavaCmdLong() string { 119 return createCmdLong(baseJavaDescription, LongVals{Process: createDefinition, Command: "create java", Result: createResult}) 120 } 121 122 func CreateShellCmdLong() string { 123 return createCmdLong(baseShellDescription, LongVals{Process: createDefinition, Command: "create shell", Result: createResult}) 124 } 125 126 func CreateNodeCmdLong() string { 127 return createCmdLong(baseNodeDescription, LongVals{Process: createDefinition, Command: "create node", Result: createResult}) 128 } 129 130 func CreatePythonCmdLong() string { 131 return createCmdLong(basePythonDescription, LongVals{Process: createDefinition, Command: "create python", Result: createResult}) 132 } 133 134 func createCmdLong(longDescr string, vals LongVals) string { 135 tmpl, err := template.New("longDescr").Parse(longDescr) 136 if err != nil { 137 panic(err) 138 } 139 140 var tpl bytes.Buffer 141 err = tmpl.Execute(&tpl, vals) 142 if err != nil { 143 panic(err) 144 } 145 146 return tpl.String() 147 }