From d4ff6411305a637c52f542df584aa1fa75b0c574 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Fri, 8 Mar 2024 14:36:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A4=B8=E2=80=8D=E2=99=80=EF=B8=8F=20m?= =?UTF-8?q?ommy=20now=20supports=20`-d`=20option=20as=20an=20alias~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ README.md | 2 +- src/main/completions/fish/mommy.fish | 2 +- src/main/completions/zsh/_mommy | 2 +- src/main/man/man1/mommy.1 | 6 +++--- src/main/sh/mommy | 4 ++-- src/test/sh/unit_spec.sh | 4 ++-- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11ac845..deba4cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## [unreleased] +### added +* πŸ€Έβ€β™€οΈ mommy now supports `-d` as an alias of `--global-config-dirs`~ + + ## [1.5.0] -- 2024-02-28 ### added * πŸ¦“ mommy now supports templates with literal slashes using `%%S%%`~ ([#107](https://github.com/FWDekker/mommy/issues/107)) diff --git a/README.md b/README.md index 5624f71..f4e9fe3 100644 --- a/README.md +++ b/README.md @@ -432,7 +432,7 @@ additionally, mommy knows a few extra options, which you can use to discover who | `-v` | `--version` | displays mommy's version information~ | | `-1` | | writes output to stdout instead of stderr~ | | `-c ` | `--config=` | tells mommy that she should read your [config](#configuration) from ``~ | -| | `--global-config-dirs=` | sets [global configuration dirs](#config-file-locations) to the colon-separated list in ``~ | +| `-d ` | `--global-config-dirs=` | sets [global configuration dirs](#config-file-locations) to the colon-separated list in ``~ | ## πŸ™‹ configuration [top β–²](#toc) diff --git a/src/main/completions/fish/mommy.fish b/src/main/completions/fish/mommy.fish index 8149bdc..249c5d6 100644 --- a/src/main/completions/fish/mommy.fish +++ b/src/main/completions/fish/mommy.fish @@ -64,7 +64,7 @@ complete --command mommy --short-option c --long-option config \ --description "Configuration file" \ --condition "not __fish_seen_argument $opt_help $opt_version"\ --condition "test -z (get_args)" -complete --command mommy --long-option global-config-dirs \ +complete --command mommy --short-option d --long-option global-config-dirs \ --require-parameter \ --arguments "(__fish_complete_directories)" \ --description "Colon-separated global config file dirs" \ diff --git a/src/main/completions/zsh/_mommy b/src/main/completions/zsh/_mommy index 1b7e282..90211fe 100644 --- a/src/main/completions/zsh/_mommy +++ b/src/main/completions/zsh/_mommy @@ -12,7 +12,7 @@ _arguments \ "(- *)"{-v,--version}'[Show version]' \ -1'[Write to stdout]' \ {-c,--config}'[Configuration file]:config:_files' \ - --global-config-dirs'[Colon-separated global config file dirs]:global config:_dir_list' \ + {-d,--global-config-dirs}'[Colon-separated global config file dirs]:global config:_dir_list' \ {-e,--eval}'[Evaluate string]:string' \ {-s,--status}'[Exit code]:code:->status' \ '*::command:' diff --git a/src/main/man/man1/mommy.1 b/src/main/man/man1/mommy.1 index 8c6773e..d05fb5c 100644 --- a/src/main/man/man1/mommy.1 +++ b/src/main/man/man1/mommy.1 @@ -41,12 +41,12 @@ note that \fIcommand\fP should be given as a single argument~ \fB-s\fP \fIstatus\fP, \fB--status=\fP\fIstatus\fP gives output corresponding to exit code \fIstatus\fP~ .TP +\fB-d\fP \fIdirs\fP, \fB--global-config-dirs=\fP\fIdirs\fP +sets global configuration dirs to the colon-separated list in \fIdirs\fP~ +.TP \fB-c\fP \fIfile\fP, \fB--config=\fP\fIfile\fP tells mommy that she should read your config from \fIfile\fP~ .TP -\fB--global-config-dirs=\fP\fIdirs\fP -sets global configuration dirs to the colon-separated list in \fIdirs\fP~ -.TP \fB-1\fP writes output to \fBstdout\fP instead of \fBstderr\fP~ diff --git a/src/main/sh/mommy b/src/main/sh/mommy index fa0f20b..388a98c 100755 --- a/src/main/sh/mommy +++ b/src/main/sh/mommy @@ -310,7 +310,7 @@ opt_global_config_dirs="${XDG_CONFIG_DIRS}:/etc/mommy/:/usr/local/etc/mommy/" opt_eval="" opt_status="" -while getopts ":hv1c:e:s:-:" OPT; do +while getopts ":hv1d:c:e:s:-:" OPT; do # Cheap workaround for long options, cf. https://stackoverflow.com/a/28466267 if [ "-" = "$OPT" ]; then OPT="${OPTARG%%=*}" @@ -323,7 +323,7 @@ while getopts ":hv1c:e:s:-:" OPT; do h|help) opt_help="1" ;; v|version) opt_version="1" ;; 1) opt_target="1" ;; - global-config-dirs) require_arg; opt_global_config_dirs="$OPTARG" ;; + d|global-config-dirs) require_arg; opt_global_config_dirs="$OPTARG" ;; c|config) opt_config="$OPTARG" ;; e|eval) require_arg; opt_eval="$OPTARG" ;; s|status) require_arg; require_int; opt_status="$OPTARG" ;; diff --git a/src/test/sh/unit_spec.sh b/src/test/sh/unit_spec.sh index 62d61a3..b24143e 100755 --- a/src/test/sh/unit_spec.sh +++ b/src/test/sh/unit_spec.sh @@ -16,8 +16,8 @@ set_config() { Describe "mommy" Describe "command-line options" It "gives an error for unknown short options" - When run "$MOMMY_EXEC" -d - The error should equal "mommy doesn't know option -d~" + When run "$MOMMY_EXEC" -z + The error should equal "mommy doesn't know option -z~" The status should be failure End From 4baa9b43e4a3c543909203734b395849f3741fc7 Mon Sep 17 00:00:00 2001 From: "Florine W. Dekker" Date: Fri, 8 Mar 2024 14:54:15 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=91=A9=E2=80=8D=F0=9F=94=AC=20mommy?= =?UTF-8?q?=20adds=20tests=20for=20the=20`-d`=20option~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/helper/spec_helper.sh | 2 +- src/test/sh/unit_spec.sh | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/helper/spec_helper.sh b/src/test/helper/spec_helper.sh index 3aaedec..94d30df 100644 --- a/src/test/helper/spec_helper.sh +++ b/src/test/helper/spec_helper.sh @@ -21,7 +21,7 @@ export MOMMY_TMP_DIR export n=" " -strip_opt() { printf "%s\n" "$1" | sed "s/[-= ]//g"; } +strip_opt() { printf "%s\n" "$1" | sed -E "s/(^-+|[= ])//g"; } ## Hooks diff --git a/src/test/sh/unit_spec.sh b/src/test/sh/unit_spec.sh index b24143e..4744705 100755 --- a/src/test/sh/unit_spec.sh +++ b/src/test/sh/unit_spec.sh @@ -75,34 +75,36 @@ Describe "mommy" End End - Describe "--global-config-dirs" - It "gives an error when no argument is given" - When run "$MOMMY_EXEC" --global-config-dirs="" -c "" true - The error should equal "mommy is missing the argument for option 'global-config-dirs'~" + Describe "-d/--global-config-dirs" + Parameters:value "-d " "--global-config-dirs=" + + It "gives an error when no argument is given using $1" + When run "$MOMMY_EXEC" $1"" -c "" true + The error should equal "mommy is missing the argument for option '$(strip_opt "$1")'~" The status should be failure End - It "uses the configuration from the file" + It "uses the configuration from the file when using $1" set_config "MOMMY_COMPLIMENTS='sport revive'" "$MOMMY_TMP_DIR/global1/config.sh" - When run "$MOMMY_EXEC" --global-config-dirs="$MOMMY_TMP_DIR/global1/" -c "" true + When run "$MOMMY_EXEC" $1"$MOMMY_TMP_DIR/global1/" -c "" true The error should equal "sport revive" The status should be success End - It "non-existing directories are skipped until an existing directory is found" + It "non-existing directories are skipped until an existing directory is found when using $1" set_config "MOMMY_COMPLIMENTS='cherry crop'" "$MOMMY_TMP_DIR/global2/config.sh" - When run "$MOMMY_EXEC" --global-config-dirs="$MOMMY_TMP_DIR/global1/:$MOMMY_TMP_DIR/global2/" -c "" true + When run "$MOMMY_EXEC" $1"$MOMMY_TMP_DIR/global1/:$MOMMY_TMP_DIR/global2/" -c "" true The error should equal "cherry crop" The status should be success End - It "when multiple global directories exist, only the first is used" + It "when multiple global directories exist, only the first is used when using $1" set_config "MOMMY_COMPLIMENTS='film style'" "$MOMMY_TMP_DIR/global1/config.sh" set_config "MOMMY_COMPLIMENTS='care smile'" "$MOMMY_TMP_DIR/global2/config.sh" - When run "$MOMMY_EXEC" --global-config-dirs="$MOMMY_TMP_DIR/global1/:$MOMMY_TMP_DIR/global2/" -c "" true + When run "$MOMMY_EXEC" $1"$MOMMY_TMP_DIR/global1/:$MOMMY_TMP_DIR/global2/" -c "" true The error should equal "film style" The status should be success End