Skip to content

Commit 119f13f

Browse files
committed
feat: add OUTPUT_DIR environment variable support to crd-extractor.sh
Allow specifying a custom output directory for generated CRD schemas by setting the OUTPUT_DIR environment variable. This enables users to generate schemas in their current directory or any specified location instead of the default ~/.datree/crdSchemas. Also updated the success message to show the actual output directory used and adjusted the example commands to use the correct path.
1 parent bfd329e commit 119f13f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Utilities/crd-extractor.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ TMP=$(mktemp -d)
5757
trap 'rm -rf "$TMP"' EXIT
5858

5959
# Create final schemas directory
60-
SCHEMAS_DIR=$HOME/.datree/crdSchemas
60+
# Use current directory if OUTPUT_DIR is set, otherwise use default
61+
SCHEMAS_DIR=${OUTPUT_DIR:-$HOME/.datree/crdSchemas}
6162
mkdir -p "$SCHEMAS_DIR"
6263
cd "$SCHEMAS_DIR"
6364

@@ -118,9 +119,10 @@ NC='\033[0m' # No Color
118119

119120
if [ $conversionResult == 0 ]; then
120121
printf "${GREEN}Successfully converted $FETCHED_CRDS CRDs to JSON schema${NC}\n"
122+
printf "Schemas saved to: ${CYAN}$SCHEMAS_DIR${NC}\n"
121123

122124
printf "\nTo validate a CR using various tools, run the relevant command:\n"
123125
printf "\n- ${CYAN}datree:${NC}\n\$ datree test /path/to/file\n"
124-
printf "\n- ${CYAN}kubeconform:${NC}\n\$ kubeconform -summary -output json -schema-location default -schema-location '$HOME/.datree/crdSchemas/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n"
125-
printf "\n- ${CYAN}kubeval:${NC}\n\$ kubeval --additional-schema-locations file:\"$HOME/.datree/crdSchemas\" /path/to/file\n\n"
126+
printf "\n- ${CYAN}kubeconform:${NC}\n\$ kubeconform -summary -output json -schema-location default -schema-location '$SCHEMAS_DIR/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' /path/to/file\n"
127+
printf "\n- ${CYAN}kubeval:${NC}\n\$ kubeval --additional-schema-locations file:\"$SCHEMAS_DIR\" /path/to/file\n\n"
126128
fi

0 commit comments

Comments
 (0)