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