Skip to content

Instantly share code, notes, and snippets.

@alexyslozada
Created November 4, 2021 04:16
Show Gist options
  • Save alexyslozada/ffdde880d7e29558eab92c1e7dbf074c to your computer and use it in GitHub Desktop.
Save alexyslozada/ffdde880d7e29558eab92c1e7dbf074c to your computer and use it in GitHub Desktop.
How to prepare some files with some parameters
#!/bin/bash
# Get the provider name
name=""
read -p "Write the provider name: " name
# Ask to dev if want to remove comments with <<>>
removeComments="N"
read -p "Do you want to remove the helpers comments? [y/N]: " removeComments
# Prepare the new names
nameLower=${name,,}
nameUpper=${name^^}
nameCap=${name^}
# Create the new package from template
cp -R template $nameLower
# Replace all words `template` by provider name
cd $nameLower
find . -type f -name "*.go" -print0 | xargs -0 sed -i "s/template/${nameLower}/g"
find . -type f -name "*.go" -print0 | xargs -0 sed -i "s/Template/${nameCap}/g"
find . -type f -name "*.go" -print0 | xargs -0 sed -i "s/TEMPLATE/${nameUpper}/g"
# Remove comments
removeComments=${removeComments,,}
if [ $removeComments == "y" ] || [ $removeComments == "yes" ]; then
find . -type f -name "*.go" -print0 | xargs -0 sed -i '/<<</d'
find . -type f -name "*.go" -print0 | xargs -0 sed -i '/>>>/d'
fi
echo "Process finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment