Created
November 4, 2021 04:16
-
-
Save alexyslozada/ffdde880d7e29558eab92c1e7dbf074c to your computer and use it in GitHub Desktop.
How to prepare some files with some parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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