From 6b2bc43d791c39309de55581e77a6dd4e6763097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega=20Froysa?= Date: Thu, 10 Nov 2022 19:58:46 +0100 Subject: [PATCH] Allow choosing port number. --- README.md | 7 ++++--- isidore.sh | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a09eaf8..dea66d0 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,15 @@ Synopsis: `isidore [options]` Commands: -- `new [-i] `: create a new project. +- `new [args] `: create a new project. - ``: new project directory. - `-i`: interactive mode. -- `build [-v] [-j]`: build the website. +- `build [args]`: build the website. - `-j`: number of jobs to run concurrently. With `0` it compiles all files at once. - `-v`: run with verbose output. -- `serve`, `server`: run an HTTP server of the output on port 8080. +- `serve`, `server [args]`: run an HTTP server of the output (default port 8080). + - `-p `: port number to bind server to. - `clean`: cleans build files. - `help`: show help information. - `version`: show Isidore version number. diff --git a/isidore.sh b/isidore.sh index 4072372..fa308f3 100755 --- a/isidore.sh +++ b/isidore.sh @@ -95,8 +95,8 @@ function print_help() Create a new Isidore project build [-v] [-j] Build the project rooted in the current directory - serve | server - Serve a local HTTP server of the output directory on port 8080 + serve | server [-p ] + Serve a local HTTP server of the output directory clean Clean the built files version @@ -281,7 +281,28 @@ case $1 in done build_project $VERBOSE $JOBS;; serve|server) - php -S localhost:8080 -t $OUTPUT_DIR/;; + PORT=8080 + shift + while getopts "p:" opt + do + case $opt in + p) + if ! [[ "$OPTARG" =~ ^[0-9]+$ ]] + then + echo "Invalid port $OPTARG. Please enter a number." + exit 1 + fi + PORT=$OPTARG;; + ?) + echo "Invalid argument $OPTARG. Use the 'help' subcommand." + print_usage + exit 1;; + :) + echo "Option -$OPTARG requires an argument." + exit 1;; + esac + done + php -S localhost:$PORT -t $OUTPUT_DIR/;; clean) clean_project;; help)