Skip to content

Commit d160ed7

Browse files
author
Mehrad
committed
update document app.create() and app.update()
1 parent a53be0c commit d160ed7

13 files changed

Lines changed: 101 additions & 160 deletions

cmd/application.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"log"
6+
67
"github.com/spf13/cobra"
78
ybApi "github.com/yottab/proto-api/proto"
89
)
@@ -108,7 +109,7 @@ func ApplicationCreate(appName, image, plan, EndpointType string, port, minScale
108109
req.Name = appName
109110
req.Plan = plan
110111
req.Values = make(map[string]string)
111-
req.Values["ports"] = fmt.Sprintf("%d/%d", port, EndpointType)
112+
req.Values["ports"] = fmt.Sprintf("%d/%s", port, EndpointType)
112113
req.Values["minimum-scale"] = fmt.Sprintf("%d", minScale)
113114
req.Values["image"] = image
114115

@@ -146,10 +147,15 @@ func appUpdate(cmd *cobra.Command, args []string) {
146147
req := new(ybApi.SrvConfigSetReq)
147148
req.Name = getCliRequiredArg(args, 0)
148149
req.Values = make(map[string]string)
149-
req.Values["minimum-scale"] = fmt.Sprintf("%d", flagVarMinScale)
150-
req.Values["ports"] = fmt.Sprintf("%d/%d", flagVarPort, flagVarEndpointType)
151-
req.Values["image"] = flagVarImage
152-
// TODO: req.Values["routes"] = flagVariableArray
150+
if flagVarMinScale != 0 {
151+
req.Values["minimum-scale"] = fmt.Sprintf("%d", flagVarMinScale)
152+
}
153+
if flagVarPort != 0 {
154+
req.Values["ports"] = fmt.Sprintf("%d/%s", flagVarPort, flagVarEndpointType)
155+
}
156+
if flagVarImage != "" {
157+
req.Values["image"] = flagVarImage
158+
}
153159
client := grpcConnect()
154160
defer client.Close()
155161

cmd/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"log"
5+
56
"github.com/spf13/cobra"
67
"github.com/spf13/viper"
78
"github.com/yottab/cli/config"

cmd/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package cmd
22

33
import (
44
"fmt"
5-
"log"
65
"io"
76
"io/ioutil"
7+
"log"
88
"os"
99
"time"
1010

cmd/color.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
package cmd
22

33
import (
4-
"github.com/fatih/color"
54
"fmt"
5+
6+
"github.com/fatih/color"
67
)
78

8-
var(
9-
mainColor = color.BgBlue
10-
secColor = color.BgYellow
11-
mainTxt = color.New(color.FgHiWhite, color.BgBlack, color.Bold)
12-
mainTxtSprint = mainTxt.SprintFunc()
13-
mainTxtColor = mainTxt.SprintfFunc()
14-
secTxtColor = color.New(color.FgWhite, color.BgBlack, color.Faint).SprintfFunc()
15-
mainTxtBlink = color.New(color.FgHiWhite, color.BgBlack, color.Bold, color.BlinkSlow).SprintfFunc()
16-
mainTitle = color.New(color.FgHiWhite, mainColor, color.Bold)
9+
var (
10+
mainColor = color.BgBlue
11+
secColor = color.BgYellow
12+
mainTxt = color.New(color.FgHiWhite, color.BgBlack, color.Bold)
13+
mainTxtSprint = mainTxt.SprintFunc()
14+
mainTxtColor = mainTxt.SprintfFunc()
15+
secTxtColor = color.New(color.FgWhite, color.BgBlack, color.Faint).SprintfFunc()
16+
mainTxtBlink = color.New(color.FgHiWhite, color.BgBlack, color.Bold, color.BlinkSlow).SprintfFunc()
17+
mainTitle = color.New(color.FgHiWhite, mainColor, color.Bold)
1718
mainTitleColor = mainTitle.SprintfFunc()
1819
mainTitlePrint = mainTitle.SprintFunc()
19-
secTitleColor = color.New(color.FgBlack, secColor, color.Bold).SprintfFunc()
20-
secTitleBlink = color.New(color.FgBlack, secColor, color.Bold, color.BlinkSlow).SprintfFunc()
21-
whiteSpace = " "
20+
secTitleColor = color.New(color.FgBlack, secColor, color.Bold).SprintfFunc()
21+
secTitleBlink = color.New(color.FgBlack, secColor, color.Bold, color.BlinkSlow).SprintfFunc()
22+
whiteSpace = " "
2223
whiteSpaceDash = " - "
2324
)
2425

25-
func mainTxtPrintln(body ...interface{}){ fmt.Println(mainTxtSprint(body...)) }
26-
func colorfulPrintln(body ...interface{}){ fmt.Println(mainTitlePrint(body...)) }
27-
func colorfulPrint(body ...interface{}){ fmt.Print(mainTitlePrint(body...)) }
26+
func mainTxtPrintln(body ...interface{}) { fmt.Println(mainTxtSprint(body...)) }
27+
func colorfulPrintln(body ...interface{}) { fmt.Println(mainTitlePrint(body...)) }
28+
func colorfulPrint(body ...interface{}) { fmt.Print(mainTitlePrint(body...)) }
2829

29-
func printKeyVal(space, k, v string){
30+
func printKeyVal(space, k, v string) {
3031
fmt.Printf("%s:%s \r\n",
3132
mainTxtColor(" %s%s ", space, k),
3233
secTxtColor(" %s ", v))
3334
}
3435

35-
func printTitleByStatus(space, title, status string){
36+
func printTitleByStatus(space, title, status string) {
3637
if status == "Unreachable" {
3738
fmt.Printf("%s%s:%s\r\n",
3839
space,
@@ -45,7 +46,7 @@ func printTitleByStatus(space, title, status string){
4546
}
4647
}
4748

48-
func printTitle(space, title string){
49+
func printTitle(space, title string) {
4950
fmt.Printf("%s%s:\r\n",
5051
space,
5152
mainTitleColor(" %s ", title))

cmd/command_cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/blang/semver"
1111
"github.com/rhysd/go-github-selfupdate/selfupdate"
12-
"github.com/spf13/cobra"
12+
"github.com/spf13/cobra"
1313
)
1414

1515
//version parameter parsing from compiler ldflags

cmd/command_create_update.go

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,30 @@ import (
88
var (
99
createCmd = &cobra.Command{
1010
Use: "create [command]",
11-
Short: "creates new [service|application|domain|volume|worker|config]",
11+
Short: "creates new [service|application|domain|volume]",
1212
Long: ``,
1313
Run: func(cmd *cobra.Command, args []string) {
14-
if cmd.Flag("compose-file").Changed {
15-
//NOOP
16-
// composeCreate(cmd, args)
17-
} else {
18-
cmd.Help()
19-
}
14+
cmd.Help()
2015
}}
2116

2217
appCreateCmd = &cobra.Command{
2318
Use: "application",
19+
Run: appCreate,
2420
Short: "creates a new application",
25-
Long: `Creates a new application.
26-
if no <name> is provided, one will be generated automatically.`,
27-
Run: appCreate}
21+
Long: `Creates a new application.`,
22+
Example: `
23+
$: yb create application \
24+
--image="hub.yottab.io/test/dotnetcore:aspnetapp" \
25+
--name="myaspnetapp" \
26+
--port=80
27+
28+
29+
$: yb create application \
30+
--image="hub.yottab.io/test/myworker:v1.2.3" \
31+
--name="myaspnetapp" \
32+
--min-scale=4 \
33+
--port=8080 \
34+
--endpoint-type=private`}
2835

2936
srvCreateCmd = &cobra.Command{
3037
Use: "service [PRODUCT.name]",
@@ -33,9 +40,11 @@ var (
3340
Long: `Creates a new servive.
3441
if no 'name' is provided, one will be generated automatically.`,
3542
Example: `
36-
$: yb product
43+
## Get a list of Service Plan and Required Variables
44+
$: yb product service mysql
45+
3746
$: yb create service mysql \
38-
--name=db \
47+
--name=mydb \
3948
--plan=starter \
4049
--variable="Database.password=DaRHEm@DaX" \
4150
--variable="Database.user=root"`}
@@ -51,24 +60,40 @@ var (
5160

5261
volumeCreateCmd = &cobra.Command{
5362
Use: "volume",
63+
Run: volumeCreate,
5464
Short: "create new volume",
5565
Long: `create new volume`,
56-
Run: volumeCreate}
66+
Example: `
67+
## Get a list of Volume Plans
68+
$: yb product volume
69+
70+
$: yb create volume \
71+
--name="my-volume" \
72+
--volume-type="persistant-2Gi"`}
5773

5874
bucketCreateCmd = &cobra.Command{
5975
Use: "bucket [name]",
76+
Run: bucketCreate,
6077
Short: "create an Object Storage bucket over the YOTTAb",
61-
Long: `create an Object Storage bucket over the YOTTAb`,
62-
Run: bucketCreate}
78+
Long: `create an Object Storage bucket over the YOTTAb`}
6379
)
6480

6581
// Update Command
6682
var (
6783
updateCmd = &cobra.Command{
6884
Use: "update [APP.name]",
85+
Run: appUpdate,
6986
Short: "update the config of existing application",
7087
Long: `This subcommand Update an existing application.`,
71-
Run: appUpdate}
88+
Example: `
89+
## The Application Version is updated
90+
$: yb update myadmin \
91+
--image="hub.yottab.io/test/myadmin:v1.2.3"
92+
93+
94+
## The Application Scale is updated
95+
$: yb update myadmin \
96+
--min-scale=4`}
7297
)
7398

7499
func init() {
@@ -103,9 +128,8 @@ func init() {
103128
// Application Update
104129
updateCmd.Flags().Uint64VarP(&flagVarPort, "port", "p", 0, "port of application")
105130
updateCmd.Flags().StringVarP(&flagVarImage, "image", "i", "", "image of application")
106-
updateCmd.Flags().Uint64VarP(&flagVarMinScale, "min-scale", "m", 1, "min scale of application")
107-
updateCmd.Flags().StringVarP(&flagVarEndpointType, "endpoint-type", "e", "http", "Accepted values: http|grpc, default to http")
108-
updateCmd.Flags().StringArrayVarP(&flagVariableArray, "routes", "r", nil, "Routes of application")
131+
updateCmd.Flags().Uint64VarP(&flagVarMinScale, "min-scale", "m", 0, "min scale of application")
132+
updateCmd.Flags().StringVarP(&flagVarEndpointType, "endpoint-type", "e", "http", "Accepted values: http|grpc|private")
109133

110134
rootCmd.AddCommand(
111135
createCmd,

cmd/command_enviroment.go

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@ import (
44
"github.com/spf13/cobra"
55
)
66

7-
// Comment
87
var (
9-
commentShort = "environment variables [Set/Unset] for an Application or Service"
10-
commentSetLong = `Add list of environment variables to an Application or Service.`
11-
commentUnsetLong = `Remove list of environment variables for an Application or Service.`
8+
commentShort = "environment variables [Set/Unset] for an Application"
9+
commentSetLong = `Add list of environment variables to an Application.`
10+
commentUnsetLong = `Remove list of environment variables for an Application.`
1211
commentExample = `
13-
$: yb environment unset application <app_name>
14-
-v="<key>"
15-
-v="<key>"
12+
$: yb environment unset my-admin
13+
-v="key1"
14+
-v="key2"
1615
17-
$: yb environment set application <app_name>
18-
-v="<key>=<value>"
19-
-v="<key>=<value>"`
16+
$: yb environment set my-admin
17+
-v="key1=value1"
18+
-v="key2=value2"`
2019
)
2120

22-
// Set Environment
2321
var (
2422
envCmd = &cobra.Command{
2523
Use: "environment [command]",
@@ -31,83 +29,32 @@ var (
3129
}}
3230

3331
setEnvCmd = &cobra.Command{
34-
Use: "set [type]",
35-
Short: commentShort,
36-
Long: commentSetLong,
37-
Example: commentExample,
38-
Run: func(cmd *cobra.Command, args []string) {
39-
cmd.Help()
40-
}}
41-
42-
appSetEnvCmd = &cobra.Command{
43-
Use: "application [name]",
32+
Use: "set [app.name]",
4433
Run: appAddEnvironmentVariable,
4534
Short: commentShort,
4635
Long: commentSetLong,
4736
Example: commentExample}
4837

49-
srvSetEnvCmd = &cobra.Command{
50-
Use: "service [name]",
51-
Run: srvEnvironmentSet,
52-
Short: commentShort,
53-
Long: commentSetLong,
54-
Example: commentExample}
55-
)
56-
57-
// UnSet Environment
58-
var (
5938
unsetEnvCmd = &cobra.Command{
60-
Use: "unset [type]",
61-
Short: commentShort,
62-
Long: commentUnsetLong,
63-
Example: commentExample,
64-
Run: func(cmd *cobra.Command, args []string) {
65-
cmd.Help()
66-
}}
67-
68-
appUnsetEnvCmd = &cobra.Command{
69-
Use: "application [name]",
39+
Use: "unset [app.name]",
7040
Run: appRemoveEnvironmentVariable,
7141
Short: commentShort,
7242
Long: commentUnsetLong,
7343
Example: commentExample}
74-
75-
srvUnsetEnvCmd = &cobra.Command{
76-
Use: "service [name]",
77-
Run: srvEnvironmentUnset,
78-
Short: commentShort,
79-
Long: commentUnsetLong,
80-
Example: commentExample}
8144
)
8245

8346
func init() {
84-
// srv set flag:
85-
srvSetEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of the service")
86-
srvSetEnvCmd.MarkFlagRequired("variable")
87-
88-
// srv unset flag:
89-
srvUnsetEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of the service")
90-
srvUnsetEnvCmd.MarkFlagRequired("variable")
91-
9247
// app set flag:
93-
appSetEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of application")
94-
appSetEnvCmd.MarkFlagRequired("variable")
48+
setEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of application")
49+
setEnvCmd.MarkFlagRequired("variable")
9550

9651
// app unset flag:
97-
appUnsetEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of application")
98-
appUnsetEnvCmd.MarkFlagRequired("variable")
52+
unsetEnvCmd.Flags().StringArrayVarP(&flagVariableArray, "variable", "v", nil, "Environment Variable of application")
53+
unsetEnvCmd.MarkFlagRequired("variable")
9954

10055
// Add the commands Environment Variable
10156
rootCmd.AddCommand(envCmd)
10257
envCmd.AddCommand(
10358
setEnvCmd,
10459
unsetEnvCmd)
105-
106-
setEnvCmd.AddCommand(
107-
appSetEnvCmd,
108-
srvSetEnvCmd)
109-
110-
unsetEnvCmd.AddCommand(
111-
appUnsetEnvCmd,
112-
srvUnsetEnvCmd)
11360
}

cmd/command_link.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"log"
5+
56
"github.com/spf13/cobra"
67
)
78

@@ -14,7 +15,7 @@ var (
1415
[Application <-> Volume]
1516
[Application <-> Domain]
1617
[Service <-> Domain]`,
17-
Example: `
18+
Example: `
1819
$: yb link set \
1920
--service="my-wordpress" \
2021
--domain="example.com"`,

cmd/command_listType.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"log"
5+
56
"github.com/spf13/cobra"
67
)
78

cmd/domain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"log"
5+
56
"github.com/spf13/cobra"
67
ybApi "github.com/yottab/proto-api/proto"
78
)

0 commit comments

Comments
 (0)