github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/scripts/api-new-type.sh (about)

     1  #!/bin/bash
     2  #
     3  # Generates a new datatype for the Tilt API server.
     4  
     5  set -e
     6  
     7  DIR=$(dirname "$0")
     8  cd "$DIR/.."
     9  
    10  TYPE_NAME="$1"
    11  if [[ "$TYPE_NAME" == "" ]]; then
    12      echo "Usage: api-new-type.sh [TypeName]"
    13      exit 1
    14  fi
    15  
    16  # Each type name has two forms
    17  # - the kind (DoThing)
    18  # - the resource (dothing)
    19  # where the first is used in YAML and the second is used in HTTP endpoints
    20  #
    21  # shellcheck disable=SC2001
    22  TYPE_NAME_LOWER=$(echo "$TYPE_NAME" | awk '{print tolower($0)}')
    23  if [[ "$TYPE_NAME" == "$TYPE_NAME_LOWER" ]]; then
    24      echo "Error: type name must be uppercase"
    25      exit 1
    26  fi
    27  
    28  OUTPUT_FILE=pkg/apis/core/v1alpha1/"$TYPE_NAME_LOWER"_types.go
    29  sed -e "s/Manifest/$TYPE_NAME/g" scripts/api-new-type-boilerplate.go.txt | \
    30      sed -e "s/manifest/$TYPE_NAME_LOWER/g" > \
    31      "$OUTPUT_FILE"
    32  
    33  echo "Successfully generated $TYPE_NAME: $OUTPUT_FILE"
    34  echo "Please add it to the list of types in pkg/apis/core/v1alpha1/register.go"
    35  echo "To generate clients for your new type:"
    36  echo "> make update-codegen"