Skip to content

Commit

Permalink
updated runme.bh (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-Mentasti authored and tstreamDOTh committed Oct 5, 2018
1 parent ca157d7 commit 3cf55d5
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Make sure you adhere to the `algorithm/language/file` folder structure while add
Additionally we recommend using standard convention for your language such as indentation and variable naming while writing the algorithm.
Useful comments will be a help. Finally, if you can write tests for you code, we urge you to do so.

**Easiest way (Recommended) ⭐️ - You can run `bash runme.bh` to make the appropriate file structure.**

## Any contributions you make will be under the MIT License
In short, when you submit code changes, your submissions are understood to be under the same MIT License
that covers the project. Feel free to contact the maintainers if that's a concern.
Expand Down
107 changes: 107 additions & 0 deletions runme.bh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash

intro() {
echo "Thank you for forking CodeZila"
echo "Please input any names without any special characters"
echo "For example: 'Insertion Sort' or 'Linked Lists'"
read -p "What is the name of the algorithm or design you want to implement? " algorithm
checkInput "$algorithm"
pickLanguague "$algorithm"
printTree "$algorithm" "$language"
checkDir "$algorithm"
}

# Checks the input to see if it does not have illegal characters
checkInput() {
# $1 is the string being checked
if [[ "$1" == *['!'@\$%^\&*()_+]* ]]
then
echo "Illegal character used"
exit
fi
}

# Asks the user that language they would like to use
pickLanguague() {
echo "Select the language you want to implement "$1" in?"
echo "1) C++"
echo "2) C"
echo "3) C#"
echo "4) Java"
echo "5) JavaScript"
echo "6) GoLang"
echo "7) Python"
echo "8) Ruby"
echo "9) Other"
read n
case $n in
1) language='C++';;
2) language='C';;
3) language='C#';;
4) language='Java';;
5) language='JavaScript';;
6) language='GoLang';;
7) language='Python';;
8) language='Ruby';;
9) inputLanguage "$1";;
*) echo "Error" ; exit;;
esac

createDir "$1" "$language"
}

inputLanguage() {
read -p "What language do you want to implement '$1' in? " lang
checkInput "$lang"
createDir "$1" "$lang"
printTree "$1" "$lang"
checkDir
exit
}

# Shows the user the created file structure
printTree() {
echo "$1"
echo "├── readme.md"
echo "└── $2"
}

# Creates the file structure
createDir() {
if [ ! -d "$1" ]
then
mkdir "$1"
fi

if [ ! -d "$1/$2" ]
then
mkdir "$1"/$2
fi
createReadme "$1" "$2"
}

createReadme() {
if [ -e "$1"/"$2"/readme.md ]
then
echo "readme file already exists for '$1/$2'"
else
read -p "Do you want to create a Readme (y/n)? " response
case "$response" in
y|Y ) echo "# $1 implemented in $2" > "$1"/"$2"/readme.md;;
n|N ) ;;
* ) echo "Readme not created" ;;
esac
fi
}

# Asks the user if they want to keep the files
checkDir() {
read -p "Is the file structure above correct? (y/n)? " choice
case "$choice" in
y|Y ) echo "Enjoy Coding!";;
n|N ) echo "Files Deleted"; rm -rf $1 ;;
* ) echo "invalid - Files not deleted";;
esac
}

intro

0 comments on commit 3cf55d5

Please sign in to comment.