Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤸‍♀️ mommy now supports -d option as an alias~ #119

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file>` | `--config=<file>` | tells mommy that she should read your [config](#configuration) from `<file>`~ |
| | `--global-config-dirs=<dirs>` | sets [global configuration dirs](#config-file-locations) to the colon-separated list in `<dirs>`~ |
| `-d <dirs>` | `--global-config-dirs=<dirs>` | sets [global configuration dirs](#config-file-locations) to the colon-separated list in `<dirs>`~ |


## 🙋 configuration<a name="configuration"></a> <small><sup>[top ▲](#toc)</sup></small>
Expand Down
2 changes: 1 addition & 1 deletion src/main/completions/fish/mommy.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion src/main/completions/zsh/_mommy
Original file line number Diff line number Diff line change
Expand Up @@ -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:'
Expand Down
6 changes: 3 additions & 3 deletions src/main/man/man1/mommy.1
Original file line number Diff line number Diff line change
Expand Up @@ -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~

Expand Down
4 changes: 2 additions & 2 deletions src/main/sh/mommy
Original file line number Diff line number Diff line change
Expand Up @@ -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%%=*}"
Expand All @@ -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" ;;
Expand Down
2 changes: 1 addition & 1 deletion src/test/helper/spec_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions src/test/sh/unit_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down