Add interactive mode to new project subcommand.

This commit is contained in:
Nicolás A. Ortega Froysa 2022-11-07 19:50:41 +01:00
parent d997d829b5
commit 76308dc9a9

View File

@ -86,8 +86,8 @@ function print_help()
{ {
print_usage print_usage
echo -e "\nCOMMANDS: echo -e "\nCOMMANDS:
new <dir> <name> new [-i] <dir>
Create a new Isidore project Create a new Isidore project (use interactive mode with '-i')
build build
Build the project rooted in the current directory Build the project rooted in the current directory
clean clean
@ -115,14 +115,22 @@ function check_in_project()
# #
# Params: # Params:
# $1 - The project directory # $1 - The project directory
# $2 - The project name # $2 - Interactive mode (1 = true; 0 = false)
## ##
function new_project() function new_project()
{ {
echo "$PROJECT_NAME v$ISIDORE_VERSION" echo "$PROJECT_NAME v$ISIDORE_VERSION"
NEW_PROJECT_DIR=$1 NEW_PROJECT_DIR=$1
NEW_PROJECT_NAME=$2 NEW_PROJECT_NAME="New Project"
NEW_PROJECT_URL="http://example.com/"
if [ $2 == 1 ]
then
echo -n "Project name: "
read NEW_PROJECT_NAME
echo -n "URL: "
read NEW_PROJECT_URL
fi
mkdir $NEW_PROJECT_DIR mkdir $NEW_PROJECT_DIR
mkdir -p $NEW_PROJECT_DIR/site/ mkdir -p $NEW_PROJECT_DIR/site/
mkdir -p $NEW_PROJECT_DIR/templates/ mkdir -p $NEW_PROJECT_DIR/templates/
@ -130,11 +138,12 @@ function new_project()
"<?php "<?php
\$site_name = \"$NEW_PROJECT_NAME\"; \$site_name = \"$NEW_PROJECT_NAME\";
\$site_author = \"$ISIDORE_AUTHOR_NAME\"; \$site_author = \"$ISIDORE_AUTHOR_NAME\";
\$site_url = \"\"; \$site_url = \"$NEW_PROJECT_URL\";
?>" >> $NEW_PROJECT_DIR/config.php ?>" >> $NEW_PROJECT_DIR/config.php
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
echo "New project created." echo "New project created."
[ $2 == 0 ] &&
echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file." echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file."
} }
@ -183,7 +192,31 @@ set_config_vars
case $1 in case $1 in
new) new)
new_project $2 $3;; if [ $# -lt 2 ]
then
echo "Insufficient number of arguments."
print_usage
exit 1
fi
INTERACTIVE=0
NEW_DIR=""
for i in ${@:2}
do
case $i in
-i)
INTERACTIVE=1;;
*)
if [ -z "$NEW_DIR" ]
then
NEW_DIR="$i"
else
echo "Unknown argument for new '$i'. Use the 'help' command."
print_usage
exit 1
fi
esac
done
new_project $NEW_DIR $INTERACTIVE;;
build) build)
build_project;; build_project;;
clean) clean)
@ -194,5 +227,6 @@ case $1 in
echo "$PROJECT_NAME v$ISIDORE_VERSION";; echo "$PROJECT_NAME v$ISIDORE_VERSION";;
*) *)
echo "Unknown command $1. Use the 'help' command." echo "Unknown command $1. Use the 'help' command."
print_usage;; print_usage
exit 1;;
esac esac