@@ -9,12 +9,13 @@ import (
99)
1010
1111var (
12- diskSize int
13- allowDowntime bool
12+ resizeInstanceID string
13+ diskSize int
14+ allowDowntime bool
1415)
1516
1617var instanceResizeCmd = & cobra.Command {
17- Use : "resize <id>" ,
18+ Use : "resize --id <id>" ,
1819 Short : "Resize instance disk" ,
1920 Long : `Resize the disk size of an instance. Default behavior is to expand the disk without any downtime.
2021Currently limited to instances in Amazon Web Services (AWS) and Google Compute Engine (GCE).
@@ -24,18 +25,21 @@ Note: This action is asynchronous. The request will return almost immediately. T
2425Note: Due to restrictions from cloud providers, it's only possible to resize the disk every 8 hours unless --allow-downtime is set.
2526
2627Available disk sizes: 0, 25, 50, 100, 250, 500, 1000, 2000 GB` ,
27- Example : ` cloudamqp instance resize 1234 --disk-size=100
28- cloudamqp instance resize 1234 --disk-size=250 --allow-downtime` ,
29- Args : cobra .ExactArgs (1 ),
30- ValidArgsFunction : completeInstances ,
28+ Example : ` cloudamqp instance resize --id 1234 --disk-size=100
29+ cloudamqp instance resize --id 1234 --disk-size=250 --allow-downtime` ,
30+ Args : cobra .NoArgs ,
3131 RunE : func (cmd * cobra.Command , args []string ) error {
3232 var err error
3333 apiKey , err = getAPIKey ()
3434 if err != nil {
3535 return fmt .Errorf ("failed to get API key: %w" , err )
3636 }
3737
38- instanceID , err := strconv .Atoi (args [0 ])
38+ if resizeInstanceID == "" {
39+ return fmt .Errorf ("--id is required" )
40+ }
41+
42+ instanceID , err := strconv .Atoi (resizeInstanceID )
3943 if err != nil {
4044 return fmt .Errorf ("invalid instance ID: %v" , err )
4145 }
@@ -75,7 +79,10 @@ Available disk sizes: 0, 25, 50, 100, 250, 500, 1000, 2000 GB`,
7579}
7680
7781func init () {
82+ instanceResizeCmd .Flags ().StringVar (& resizeInstanceID , "id" , "" , "Instance ID (required)" )
7883 instanceResizeCmd .Flags ().IntVar (& diskSize , "disk-size" , 0 , "Disk size to add in gigabytes (0, 25, 50, 100, 250, 500, 1000, 2000)" )
7984 instanceResizeCmd .Flags ().BoolVar (& allowDowntime , "allow-downtime" , false , "Allow cluster downtime if needed when resizing disk" )
85+ instanceResizeCmd .MarkFlagRequired ("id" )
8086 instanceResizeCmd .MarkFlagRequired ("disk-size" )
87+ instanceResizeCmd .RegisterFlagCompletionFunc ("id" , completeInstances )
8188}
0 commit comments