From 76308dc9a99e03e820c58cfcc249ddf0833c37ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega=20Froysa?= Date: Mon, 7 Nov 2022 19:50:41 +0100 Subject: [PATCH] Add interactive mode to new project subcommand. --- isidore.sh | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/isidore.sh b/isidore.sh index b15800a..950e349 100755 --- a/isidore.sh +++ b/isidore.sh @@ -86,8 +86,8 @@ function print_help() { print_usage echo -e "\nCOMMANDS: - new - Create a new Isidore project + new [-i] + Create a new Isidore project (use interactive mode with '-i') build Build the project rooted in the current directory clean @@ -115,14 +115,22 @@ function check_in_project() # # Params: # $1 - The project directory -# $2 - The project name +# $2 - Interactive mode (1 = true; 0 = false) ## function new_project() { echo "$PROJECT_NAME v$ISIDORE_VERSION" 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 -p $NEW_PROJECT_DIR/site/ mkdir -p $NEW_PROJECT_DIR/templates/ @@ -130,12 +138,13 @@ function new_project() "" >> $NEW_PROJECT_DIR/config.php echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version echo "New project created." - echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file." + [ $2 == 0 ] && + echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file." } ## @@ -183,7 +192,31 @@ set_config_vars case $1 in 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_project;; clean) @@ -194,5 +227,6 @@ case $1 in echo "$PROJECT_NAME v$ISIDORE_VERSION";; *) echo "Unknown command $1. Use the 'help' command." - print_usage;; + print_usage + exit 1;; esac