@@ -85,6 +85,36 @@ func NewCmd(p *print.Printer) *cobra.Command {
8585 `$ stackit beta server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64` ,
8686 ),
8787 ),
88+ PreRun : func (cmd * cobra.Command , _ []string ) {
89+ bootVolumeSourceId , _ := cmd .Flags ().GetString (bootVolumeSourceIdFlag )
90+ bootVolumeSourceType , _ := cmd .Flags ().GetString (bootVolumeSourceTypeFlag )
91+ bootVolumeSize , _ := cmd .Flags ().GetInt64 (bootVolumeSizeFlag )
92+ imageId , _ := cmd .Flags ().GetString (imageIdFlag )
93+
94+ if imageId == "" && bootVolumeSourceId == "" && bootVolumeSourceType == "" {
95+ p .Warn ("Either Image ID or boot volume flags must be provided.\n " )
96+ }
97+
98+ if imageId == "" {
99+ err := flags .MarkFlagsRequired (cmd , bootVolumeSourceIdFlag , bootVolumeSourceTypeFlag )
100+ cobra .CheckErr (err )
101+ }
102+
103+ if bootVolumeSourceType == "image" {
104+ if bootVolumeSize == 0 {
105+ p .Warn ("Boot volume size must be provided when `source_type` is `image`.\n " )
106+ }
107+ cmd .MarkFlagRequired (bootVolumeSizeFlag )
108+ }
109+
110+ if bootVolumeSourceId == "" && bootVolumeSourceType == "" {
111+ cmd .MarkFlagRequired (imageIdFlag )
112+ }
113+
114+ if imageId != "" && (bootVolumeSourceId != "" || bootVolumeSourceType != "" ) {
115+ p .Warn ("Image ID flag cannot be used together with any of the boot volume flags.\n " )
116+ }
117+ },
88118 RunE : func (cmd * cobra.Command , _ []string ) error {
89119 ctx := context .Background ()
90120 model , err := parseInput (p , cmd )
0 commit comments