opts: add working-directory option v1.2.0
authoralex <[email protected]>
Sat, 21 Dec 2024 19:17:24 +0000 (11:17 -0800)
committeralex <[email protected]>
Sat, 21 Dec 2024 19:26:14 +0000 (11:26 -0800)
mirror-all

index 8ccbd8e7e9ded1784d12057e3d70a1dc21db7965..1bed52a13bfae9dc5e8dfb20f4de56b5013195f5 100755 (executable)
@@ -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 <directory>"
        exit 1
 }
 
@@ -229,6 +237,8 @@ main() {
        clone_repos
        fetch_repos
 
+       set_working_directory "$PWD"
+
        log "Successfully updated repos"
 
        exit