mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 01:56:39 +00:00
Remove dotfile option parsing commands
They are no longer needed, as I'm going for a "compile Dotfile to regular shell script" approach now, rather than a "manually parse the shit out of the Dotfile".
This commit is contained in:
@@ -43,7 +43,6 @@ source "../lib/internals/create-symlink.sh"
|
||||
source "../lib/internals/execute-dotfile.sh"
|
||||
source "../lib/internals/locate-dotfile.sh"
|
||||
source "../lib/internals/locate-target.sh"
|
||||
source "../lib/internals/parse-dotfile-options.sh"
|
||||
|
||||
#
|
||||
# Command functions
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# Parse Dotfile options and set relevant global variables.
|
||||
parse-dotfile-options() {
|
||||
DOTIFY_OPT_ROOT_LINK="$(parse-dotfile-root_link-option)"
|
||||
DOTIFY_OPT_DEFAULT_ACTION="$(parse-dotfile-default_action-option)"
|
||||
}
|
||||
|
||||
# Parse root_link option.
|
||||
parse-dotfile-root_link-option() {
|
||||
echo "$(parse-dotfile-option "root_link" ".dotfiles" "$1")"
|
||||
}
|
||||
|
||||
# Parse default_action option.
|
||||
parse-dotfile-default_action-option() {
|
||||
echo "$(parse-dotfile-option "default_action" "link" "$1")"
|
||||
}
|
||||
|
||||
# Extract a specific option from Dotfile.
|
||||
#
|
||||
# Arguments:
|
||||
# - $1: Name of option to extract.
|
||||
# - $2: (optional) Default value of option if not present in Dotfile.
|
||||
# - $3: (optional) Specific Dotfile to read. Uses $DOTFILE if empty.
|
||||
#
|
||||
parse-dotfile-option() {
|
||||
local name="$1"
|
||||
local value="$2"
|
||||
local dotfile="$3"
|
||||
if [ -z "$dotfile" ]; then dotfile="$DOTFILE"; fi
|
||||
|
||||
local line=""
|
||||
while read line; do
|
||||
if [[ "$line" == "$name "* ]]; then
|
||||
value="$(trim "${line/#$name }")"
|
||||
break
|
||||
fi
|
||||
done < "$dotfile"
|
||||
|
||||
echo "$value"
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "../../../src/lib/helpers/trim.sh"
|
||||
source "../../../src/lib/internals/parse-dotfile-options.sh"
|
||||
|
||||
#
|
||||
# parse-dotfile-options() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-root_link-option"
|
||||
stub "parse-dotfile-default_action-option"
|
||||
|
||||
parse-dotfile-options
|
||||
assert 'echo "$DOTIFY_OPT_ROOT_LINK"' \
|
||||
"parse-dotfile-root_link-option stub: "
|
||||
assert 'echo "$DOTIFY_OPT_DEFAULT_ACTION"' \
|
||||
"parse-dotfile-default_action-option stub: "
|
||||
|
||||
restore "parse-dotfile-root_link-option"
|
||||
restore "parse-dotfile-default_action-option"
|
||||
|
||||
|
||||
assert_end "parse-dotfile-options()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-option() tests
|
||||
#
|
||||
|
||||
# Create temp files/folders used for locate-dotfile() tests.
|
||||
mkdir -p "test-tmp/with" "test-tmp/without"
|
||||
echo -e "foo_bar .things\nlink: foo -> .foo" > "test-tmp/with/Dotfile"
|
||||
echo -e "link: foo -> .foo" > "test-tmp/without/Dotfile"
|
||||
|
||||
# When $DOTFILE contains root_link option.
|
||||
DOTFILE="test-tmp/with/Dotfile"
|
||||
assert 'parse-dotfile-option foo_bar .none' ".things"
|
||||
unset DOTFILE
|
||||
|
||||
# When $DOTFILE does not contain root_link option.
|
||||
DOTFILE="test-tmp/without/Dotfile"
|
||||
assert 'parse-dotfile-option foo_bar .none' ".none"
|
||||
unset DOTFILE
|
||||
|
||||
# When Dotfile to parse is specified as argument.
|
||||
assert 'parse-dotfile-option foo_bar .none test-tmp/with/Dotfile' ".things"
|
||||
assert 'parse-dotfile-option foo_bar .none test-tmp/without/Dotfile' ".none"
|
||||
|
||||
# When option is wrapped across multiple lines with a backslash.
|
||||
echo 'foo_bar \' > "test-tmp/with/Dotfile"
|
||||
echo ' .things' >> "test-tmp/with/Dotfile"
|
||||
echo 'link: foo -> bar' >> "test-tmp/with/Dotfile"
|
||||
DOTFILE="test-tmp/with/Dotfile"
|
||||
assert 'parse-dotfile-option foo_bar .none' ".things"
|
||||
unset DOTFILE
|
||||
|
||||
# Remove temp files/folders used for locate-dotfile() tests.
|
||||
rm "test-tmp/with/Dotfile" "test-tmp/without/Dotfile"
|
||||
rmdir "test-tmp/with" "test-tmp/without" "test-tmp"
|
||||
|
||||
assert_end "parse-dotfile-option()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-root_link-option() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-option"
|
||||
assert 'parse-dotfile-root_link-option' \
|
||||
'parse-dotfile-option stub: root_link .dotfiles '
|
||||
assert 'parse-dotfile-root_link-option "test-tmp/with/Dotfile"' \
|
||||
'parse-dotfile-option stub: root_link .dotfiles test-tmp/with/Dotfile'
|
||||
restore "parse-dotfile-option"
|
||||
|
||||
assert_end "parse-dotfile-root_link-option()"
|
||||
|
||||
|
||||
#
|
||||
# parse-dotfile-default_action-option() tests
|
||||
#
|
||||
|
||||
stub "parse-dotfile-option"
|
||||
assert 'parse-dotfile-default_action-option' \
|
||||
'parse-dotfile-option stub: default_action link '
|
||||
assert 'parse-dotfile-default_action-option "test-tmp/with/Dotfile"' \
|
||||
'parse-dotfile-option stub: default_action link test-tmp/with/Dotfile'
|
||||
restore "parse-dotfile-option"
|
||||
|
||||
assert_end "parse-dotfile-default_action-option()"
|
||||
Reference in New Issue
Block a user