Skip to content

Commit

Permalink
feat: make it possible to add parameters to required capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Mar 20, 2020
1 parent 2dbe5fb commit a951dd8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/hal/cli/component/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
v1beta13 "halkyon.io/api/capability/v1beta1"
"halkyon.io/api/component/v1beta1"
v1beta12 "halkyon.io/api/runtime/v1beta1"
halkyon "halkyon.io/api/v1beta1"
"halkyon.io/hal/pkg/cmdutil"
"halkyon.io/hal/pkg/hal/cli/capability"
"halkyon.io/hal/pkg/io"
Expand Down Expand Up @@ -165,6 +166,21 @@ func (o *createOptions) Complete(name string, cmd *cobra.Command, args []string)
required.Spec = capCreate.AsCapabilitySpec()
required.AutoBindable = ui.Proceed("Auto-bindable")
}
if ui.Proceed("Add extra parameters") {
for {
paramPair := ui.AskOrReturnToExit("Parameter in the 'name=value' format, simply press enter when finished")
if len(paramPair) == 0 {
break
}
split := strings.Split(paramPair, "=")
if len(split) != 2 {
return fmt.Errorf("invalid parameter: %s, format must be 'name=value'", paramPair)
}
param := halkyon.NameValuePair{Name: split[0], Value: split[1]}
required.Spec.Parameters = append(required.Spec.Parameters, param)
ui.OutputSelection("Set parameter", fmt.Sprintf("%s=%s", param.Name, param.Value))
}
}
o.requiredCaps = append(o.requiredCaps, required)
}
}
Expand All @@ -181,6 +197,9 @@ func (o *createOptions) Complete(name string, cmd *cobra.Command, args []string)
if err := capCreate.Complete(); err != nil {
return err
}
if err := capCreate.Validate(); err != nil {
return err
}
provided.Spec = capCreate.AsCapabilitySpec()
o.providedCaps = append(o.providedCaps, provided)
}
Expand Down

0 comments on commit a951dd8

Please sign in to comment.