From 357122096d4dd0ca5921f4b49dc894102b70e095 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 21 Dec 2024 11:17:24 -0800 Subject: [PATCH] opts: add working-directory option --- mirror-all | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mirror-all b/mirror-all index 8ccbd8e..1bed52a 100755 --- a/mirror-all +++ b/mirror-all @@ -164,17 +164,19 @@ parse_arguments() { case "$arg" in "--quiet") set -- "$@" "-q" ;; "--verbose") set -- "$@" "-v" ;; + "--working-directory") set -- "$@" "-w" ;; *) set -- "$@" "$arg" ;; esac done # parse short options OPTIND=1 - while getopts "qv" opt + while getopts "qvw:" opt do case "$opt" in "q") set_loglevel "error" ;; "v") set_loglevel "info" ;; + "w") set_working_directory "$OPTARG" ;; "?") usage ;; esac done @@ -202,6 +204,11 @@ set_loglevel() { esac } +set_working_directory() { + log_info "changing working directory to $1" + cd "$1" +} + usage() { log_err "Usage:" log_err "" @@ -210,6 +217,7 @@ usage() { log_err "Options:" log_err "\t--quiet, -q" log_err "\t--verbose, -v" + log_err "\t--working-directory, -w " exit 1 } @@ -229,6 +237,8 @@ main() { clone_repos fetch_repos + set_working_directory "$PWD" + log "Successfully updated repos" exit -- 2.30.2