newLint.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Script to create new lint from template
  2. USAGE="Usage: $0 <ARG1> <ARG2> <ARG3>
  3. ARG1: Path_name
  4. ARG2: File_name/TestName (no 'lint_' prefix)
  5. ARG3: Struct_name"
  6. if [ $# -eq 0 ]; then
  7. echo "No arguments provided..."
  8. echo "$USAGE"
  9. exit 1
  10. fi
  11. if [ $# -eq 1 ]; then
  12. echo "Not enough arguments provided..."
  13. echo "$USAGE"
  14. exit 1
  15. fi
  16. if [ $# -eq 2 ]; then
  17. echo "Not enough arguments provided..."
  18. echo "$USAGE"
  19. exit 1
  20. fi
  21. if [ ! -d lints/$1 ]
  22. then
  23. echo "Directory 'lints/$1' does not exist. Can't make new file."
  24. exit 1
  25. fi
  26. if [ -e lints/$1/lint_$2.go ]
  27. then
  28. echo "File already exists. Can't make new file."
  29. exit 1
  30. fi
  31. PATHNAME=$1
  32. LINTNAME=$2
  33. # Remove the first two characters from ${LINTNAME} and save the resulting string into FILENAME
  34. FILENAME=${LINTNAME:2}
  35. STRUCTNAME=$3
  36. sed -e "s/PACKAGE/${PATHNAME}/" \
  37. -e "s/PASCAL_CASE_SUBST/${STRUCTNAME^}/g" \
  38. -e "s/SUBST/${STRUCTNAME}/g" \
  39. -e "s/SUBTEST/${LINTNAME}/g" template > lints/${PATHNAME}/lint_${FILENAME}.go
  40. echo "Created file lints/${PATHNAME}/lint_${FILENAME}.go with struct name ${STRUCTNAME}"