github.com/devcamcar/cli@v0.0.0-20181107134215-706a05759d18/objects/fn/commands.go (about) 1 package fn 2 3 import ( 4 client "github.com/fnproject/cli/client" 5 "github.com/urfave/cli" 6 ) 7 8 // Create function command 9 func Create() cli.Command { 10 f := fnsCmd{} 11 return cli.Command{ 12 Name: "function", 13 ShortName: "func", 14 Aliases: []string{"f", "fn"}, 15 Category: "MANAGEMENT COMMAND", 16 Usage: "Create a function within an application", 17 Description: "This command creates a new function within an application.", 18 Before: func(c *cli.Context) error { 19 var err error 20 f.provider, err = client.CurrentProvider() 21 if err != nil { 22 return err 23 } 24 f.client = f.provider.APIClientv2() 25 return nil 26 }, 27 ArgsUsage: "<app-name> <function-name> <image>", 28 Action: f.create, 29 Flags: FnFlags, 30 } 31 } 32 33 // List functions command 34 func List() cli.Command { 35 f := fnsCmd{} 36 return cli.Command{ 37 Name: "functions", 38 ShortName: "funcs", 39 Aliases: []string{"f", "fn"}, 40 Usage: "List functions for an application", 41 Category: "MANAGEMENT COMMAND", 42 Description: "This command returns a list of functions for a created application.", 43 Before: func(c *cli.Context) error { 44 var err error 45 f.provider, err = client.CurrentProvider() 46 if err != nil { 47 return err 48 } 49 f.client = f.provider.APIClientv2() 50 return nil 51 }, 52 ArgsUsage: "<app-name>", 53 Action: f.list, 54 Flags: []cli.Flag{ 55 cli.StringFlag{ 56 Name: "cursor", 57 Usage: "pagination cursor", 58 }, 59 cli.Int64Flag{ 60 Name: "n", 61 Usage: "number of functions to return", 62 Value: int64(100), 63 }, 64 cli.StringFlag{ 65 Name: "output", 66 Usage: "Output format (json)", 67 Value: "", 68 }, 69 }, 70 } 71 } 72 73 // Delete function command 74 func Delete() cli.Command { 75 f := fnsCmd{} 76 return cli.Command{ 77 Name: "function", 78 ShortName: "func", 79 Aliases: []string{"f", "fn"}, 80 Category: "MANAGEMENT COMMAND", 81 Description: "This command deletes an existing function from an application.", 82 Usage: "Delete a function from an application", 83 Before: func(c *cli.Context) error { 84 var err error 85 f.provider, err = client.CurrentProvider() 86 if err != nil { 87 return err 88 } 89 f.client = f.provider.APIClientv2() 90 return nil 91 }, 92 ArgsUsage: "<app-name> <function-name>", 93 Action: f.delete, 94 } 95 } 96 97 // Inspect function command 98 func Inspect() cli.Command { 99 f := fnsCmd{} 100 return cli.Command{ 101 Name: "function", 102 ShortName: "func", 103 Aliases: []string{"f", "fn"}, 104 Category: "MANAGEMENT COMMAND", 105 Usage: "Retrieve one or all properties for a function", 106 Description: "This command inspects properties of a function.", 107 Before: func(c *cli.Context) error { 108 var err error 109 f.provider, err = client.CurrentProvider() 110 if err != nil { 111 return err 112 } 113 f.client = f.provider.APIClientv2() 114 return nil 115 }, 116 Flags: []cli.Flag{ 117 cli.BoolFlag{ 118 Name: "endpoint", 119 Usage: "Output the function invoke endpoint if set", 120 }, 121 }, 122 ArgsUsage: "<app-name> <function-name> [property.[key]]", 123 Action: f.inspect, 124 } 125 } 126 127 // Update function command 128 func Update() cli.Command { 129 f := fnsCmd{} 130 return cli.Command{ 131 Name: "function", 132 ShortName: "func", 133 Aliases: []string{"f", "fn"}, 134 Category: "MANAGEMENT COMMAND", 135 Usage: "Update a function in application", 136 Description: "This command updates a function in an application.", 137 Before: func(c *cli.Context) error { 138 var err error 139 f.provider, err = client.CurrentProvider() 140 if err != nil { 141 return err 142 } 143 f.client = f.provider.APIClientv2() 144 return nil 145 }, 146 ArgsUsage: "<app-name> <function-name>", 147 Action: f.update, 148 Flags: updateFnFlags, 149 } 150 } 151 152 // GetConfig for function command 153 func GetConfig() cli.Command { 154 r := fnsCmd{} 155 return cli.Command{ 156 Name: "function", 157 ShortName: "func", 158 Aliases: []string{"f", "fn"}, 159 Category: "MANAGEMENT COMMAND", 160 Usage: "Inspect configuration key for this function", 161 Description: "This command gets the configuration of a specific function for an application.", 162 Before: func(c *cli.Context) error { 163 var err error 164 r.provider, err = client.CurrentProvider() 165 if err != nil { 166 return err 167 } 168 r.client = r.provider.APIClientv2() 169 return nil 170 }, 171 ArgsUsage: "<app-name> <funct> <key>", 172 Action: r.getConfig, 173 } 174 } 175 176 // SetConfig for function command 177 func SetConfig() cli.Command { 178 f := fnsCmd{} 179 return cli.Command{ 180 Name: "function", 181 ShortName: "func", 182 Aliases: []string{"f", "fn"}, 183 Category: "MANAGEMENT COMMAND", 184 Usage: "Store a configuration key for this function", 185 Description: "This command sets the configuration of a specific function for an application.", 186 Before: func(c *cli.Context) error { 187 var err error 188 f.provider, err = client.CurrentProvider() 189 if err != nil { 190 return err 191 } 192 f.client = f.provider.APIClientv2() 193 return nil 194 }, 195 ArgsUsage: "<app-name> <function-name> <key> <value>", 196 Action: f.setConfig, 197 } 198 } 199 200 // ListConfig for function command 201 func ListConfig() cli.Command { 202 f := fnsCmd{} 203 return cli.Command{ 204 Name: "function", 205 ShortName: "func", 206 Aliases: []string{"f", "fn"}, 207 Category: "MANAGEMENT COMMAND", 208 Usage: "List configuration key/value pairs for this function", 209 Description: "This command returns a list of configurations for a specific function.", 210 Before: func(c *cli.Context) error { 211 var err error 212 f.provider, err = client.CurrentProvider() 213 if err != nil { 214 return err 215 } 216 f.client = f.provider.APIClientv2() 217 return nil 218 }, 219 ArgsUsage: "<app-name> <function-name>", 220 Action: f.listConfig, 221 } 222 } 223 224 // UnsetConfig for function command 225 func UnsetConfig() cli.Command { 226 f := fnsCmd{} 227 return cli.Command{ 228 Name: "function", 229 ShortName: "func", 230 Aliases: []string{"f", "fn"}, 231 Category: "MANAGEMENT COMMAND", 232 Usage: "Remove a configuration key for this function", 233 Description: "This command removes a configuration of a specific function.", 234 Before: func(c *cli.Context) error { 235 var err error 236 f.provider, err = client.CurrentProvider() 237 if err != nil { 238 return err 239 } 240 f.client = f.provider.APIClientv2() 241 return nil 242 }, 243 ArgsUsage: "<app-name> </path> <key>", 244 Action: f.unsetConfig, 245 } 246 }