@@ -39,20 +39,30 @@ func main() {
3939 }
4040}
4141
42+ type options struct {
43+ db string
44+ size int
45+ }
46+
4247func composeCommand () * cobra.Command {
4348 c := & cobra.Command {
4449 Use : "compose EVENT" ,
4550 TraverseChildren : true ,
4651 }
4752 c .PersistentFlags ().String ("project-name" , "" , "compose project name" ) // unused
53+
54+ var options options
55+
4856 upCmd := & cobra.Command {
49- Use : "up" ,
50- Run : up ,
57+ Use : "up" ,
58+ Run : func (_ * cobra.Command , args []string ) {
59+ up (options , args )
60+ },
5161 Args : cobra .ExactArgs (1 ),
5262 }
53- upCmd .Flags ().String ( "type" , "" , "Database type (mysql, postgres, etc.)" )
63+ upCmd .Flags ().StringVar ( & options . db , "type" , "" , "Database type (mysql, postgres, etc.)" )
5464 _ = upCmd .MarkFlagRequired ("type" )
55- upCmd .Flags ().Int ( "size" , 10 , "Database size in GB" )
65+ upCmd .Flags ().IntVar ( & options . size , "size" , 10 , "Database size in GB" )
5666 upCmd .Flags ().String ("name" , "" , "Name of the database to be created" )
5767 _ = upCmd .MarkFlagRequired ("name" )
5868
@@ -71,13 +81,13 @@ func composeCommand() *cobra.Command {
7181
7282const lineSeparator = "\n "
7383
74- func up (_ * cobra. Command , args []string ) {
84+ func up (options options , args []string ) {
7585 servicename := args [0 ]
7686 fmt .Printf (`{ "type": "debug", "message": "Starting %s" }%s` , servicename , lineSeparator )
7787
78- for i := 0 ; i < 100 ; i += 10 {
88+ for i := 0 ; i < options . size ; i ++ {
7989 time .Sleep (1 * time .Second )
80- fmt .Printf (`{ "type": "info", "message": "Processing ... %d%%" }%s` , i , lineSeparator )
90+ fmt .Printf (`{ "type": "info", "message": "Processing ... %d%%" }%s` , i * 100 / options . size , lineSeparator )
8191 }
8292 fmt .Printf (`{ "type": "setenv", "message": "URL=https://magic.cloud/%s" }%s` , servicename , lineSeparator )
8393}
0 commit comments