github.com/oam-dev/kubevela@v1.9.11/hack/cuegen/cuegen.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  
     5  # Usage: cuegen.sh dir [flagsToVela]
     6  # Example: cuegen.sh references/cuegen/generators/provider/testdata/ \
     7  #           -t provider \
     8  #           --types *k8s.io/apimachinery/pkg/apis/meta/v1/unstructured.Unstructured=ellipsis
     9  
    10  
    11  # check vela binary
    12  if ! [ -x "$(command -v vela)" ]; then
    13    echo "Please put vela binary in the PATH"
    14    exit 1
    15  fi
    16  
    17  # get dir from first arg
    18  dir="$1"
    19  if [ -z "$dir" ]; then
    20    echo "Please provide a directory"
    21    exit 1
    22  fi
    23  
    24  echo "Generating CUE files from go files in $dir"
    25  echo "========"
    26  
    27  find "$dir" -name "*.go" | while read -r file; do
    28    echo "- Generating CUE file for $file"
    29  
    30    # redirect output if command exits successfully
    31    (out=$(vela def gen-cue ${*:2} "$file") && echo "$out" > "${file%.go}".cue) &
    32  done
    33  
    34  echo "========"
    35  echo "Waiting for all background processes to finish"
    36  
    37  wait
    38  sleep 5s # wait for all stderr to be printed
    39  
    40  echo "Done"