Skip to content
Snippets Groups Projects
Commit ffd62b9b authored by Alex Clemmer's avatar Alex Clemmer
Browse files

Add optional params to prototype spec

Fixes #69.

Currently we allow users to specify prototypes using Jsonnet. At the
head of each prototype should be a comment with semi-structured
metadata, e.g.,

  // @apiVersion 0.0.1
  // @name io.ksonnet.pkg.nginx-simple
  // @description Deploys a simple, stateless nginx server with server
  // blocks (roughly equivalent
  //   to nginx virtual hosts). The nginx container is deployed using a
  //   Kubernetes deployment, and is exposed to a network with a service.
  // @param namespace string default Namespace in which to put the
  // application
  // @param name string Name to give to each of the components

Critically, some metadata about params is stored using the `@param` tag,
including name, type, and description, for pretty printing.

This commit will introduce a new param type, `@optionalParam`. This type
has a name, type, default value, and description.

It is currently not possible to specify a default value with spaces, but
this should be good enough for...
parent 02b62066
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ const (
nameTag = "@name"
descriptionTag = "@description"
paramTag = "@param"
optParamTag = "@optionalParam"
)
func FromJsonnet(data string) (*SpecificationSchema, error) {
......@@ -93,7 +94,7 @@ func FromJsonnet(data string) (*SpecificationSchema, error) {
openText = bytes.Buffer{}
openText.WriteString(strings.TrimSpace(split[1]))
switch split[0] {
case apiVersionTag, nameTag, descriptionTag, paramTag: // Do nothing.
case apiVersionTag, nameTag, descriptionTag, paramTag, optParamTag: // Do nothing.
default:
return nil, fmt.Errorf(`Line in prototype heading comment is formatted incorrectly; '%s' is not
recognized as a tag. Only tags can begin lines, and text that is wrapped must
......@@ -222,6 +223,27 @@ func (s *SpecificationSchema) addField(tag, text string) error {
Default: nil,
Type: pt,
})
case optParamTag:
// NOTE: There is usually more than one `@optionalParam`, so we
// don't check length here.
split := strings.SplitN(text, " ", 4)
if len(split) < 4 {
return fmt.Errorf("Optional param fields must have '<name> <type> <default-val> <description> (<default-val> currently cannot contain spaces), but got:\n%s", text)
}
pt, err := parseParamType(split[1])
if err != nil {
return err
}
s.Params = append(s.Params, &ParamSchema{
Name: split[0],
Alias: &split[0],
Description: split[2],
Default: &split[3],
Type: pt,
})
default:
return fmt.Errorf(`Line in prototype heading comment is formatted incorrectly; '%s' is not
recognized as a tag. Only tags can begin lines, and text that is wrapped must
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment