-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes related to config loading, close #222
- fix interactive configs loading all, instead of the first - `load_dorothy_config` now accepts `--first` - fix interactive configs failing if don't exist - they are optional, don't fail - `load_dorothy_config` now accepts `--optional` - fix a secondary user config not loading if a primary default config existed - default config now only loads if none of the user config filenames exist
- Loading branch information
Showing
8 changed files
with
198 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
#!/usr/bin/env fish | ||
|
||
# for scripts and sources to load a configuration file | ||
# load_dorothy_config ...<filename> | ||
# load_dorothy_config [--first] [--silent] [--] ...<filename> | ||
function load_dorothy_config | ||
set --local dorothy_config_loaded 'no' | ||
# process arguments | ||
set --local only_first 'no' | ||
set --local optional 'no' | ||
while test (count $argv) -ne 0 | ||
switch $argv[1] | ||
case '--first' | ||
set -e argv[1] | ||
set only_first 'yes' | ||
case '--optional' | ||
set -e argv[1] | ||
set optional 'yes' | ||
case '--' | ||
set -e argv[1] | ||
break | ||
case '*' | ||
break | ||
end | ||
end | ||
|
||
# for each filename, load a single config file | ||
# load the configuration | ||
set --local filename | ||
set --local loaded 'no' | ||
# for each filename, try user/config.local otherwise user/config | ||
for filename in $argv | ||
if test -f "$DOROTHY/user/config.local/$filename" | ||
# load user/config.local/* | ||
source "$DOROTHY/user/config.local/$filename" | ||
set dorothy_config_loaded 'yes' | ||
set loaded 'yes' | ||
else if test -f "$DOROTHY/user/config/$filename" | ||
# otherwise load user/config/* | ||
# load user/config/* | ||
source "$DOROTHY/user/config/$filename" | ||
set dorothy_config_loaded 'yes' | ||
else if test -f "$DOROTHY/config/$filename" | ||
# otherwise load default configuration | ||
source "$DOROTHY/config/$filename" | ||
set dorothy_config_loaded 'yes' | ||
set loaded 'yes' | ||
end | ||
if test "$only_first" = 'yes' -a "$loaded" = 'yes' | ||
break | ||
end | ||
end | ||
# if no user-defined configuration was provided, try the same filenames, but in the default configuration | ||
if test "$loaded" = 'no' | ||
for filename in $argv | ||
if test -f "$DOROTHY/config/$filename" | ||
# load default configuration | ||
source "$DOROTHY/config/$filename" | ||
set loaded 'yes' | ||
end | ||
if test "$only_first" = 'yes' -a "$loaded" = 'yes' | ||
break | ||
end | ||
end | ||
# otherwise try next filename | ||
end | ||
|
||
# if nothing was loaded, then fail | ||
if test "$dorothy_config_loaded" = 'no' | ||
echo-style --error="Missing the configuration file: $argv" >/dev/stderr | ||
return 2 # No such file or directory | ||
if test "$loaded" = 'no' | ||
if test "$optional" = 'no' | ||
echo-style --error="Missing the configuration file: $argv" >/dev/stderr | ||
return 2 # ENOENT 2 No such file or directory | ||
end | ||
end | ||
return 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,65 @@ | ||
#!/usr/bin/env sh | ||
|
||
# for scripts and sources to load a configuration file | ||
# load_dorothy_config ...<filename> | ||
# load_dorothy_config [--first] [--silent] [--] ...<filename> | ||
load_dorothy_config() { | ||
dorothy_config_loaded='no' | ||
# process arguments | ||
load_dorothy_config__only_first='no' load_dorothy_config__optional='no' | ||
while test "$#" -ne 0; do | ||
case "$1" in | ||
'--first') | ||
shift | ||
load_dorothy_config__only_first='yes' | ||
;; | ||
'--optional') | ||
shift | ||
load_dorothy_config__optional='yes' | ||
;; | ||
'--') | ||
shift | ||
break | ||
;; | ||
*) break ;; | ||
esac | ||
done | ||
|
||
# for each filename, load a single config file | ||
for dorothy_config_filename in "$@"; do | ||
if test -f "$DOROTHY/user/config.local/$dorothy_config_filename"; then | ||
# load the configuration | ||
load_dorothy_config__loaded='no' | ||
# for each filename, try user/config.local otherwise user/config | ||
for load_dorothy_config__filename in "$@"; do | ||
if test -f "$DOROTHY/user/config.local/$load_dorothy_config__filename"; then | ||
# load user/config.local/* | ||
. "$DOROTHY/user/config.local/$dorothy_config_filename" | ||
dorothy_config_loaded='yes' | ||
elif test -f "$DOROTHY/user/config/$dorothy_config_filename"; then | ||
# otherwise load user/config/* | ||
. "$DOROTHY/user/config/$dorothy_config_filename" | ||
dorothy_config_loaded='yes' | ||
elif test -f "$DOROTHY/config/$dorothy_config_filename"; then | ||
# otherwise load default configuration | ||
. "$DOROTHY/config/$dorothy_config_filename" | ||
dorothy_config_loaded='yes' | ||
. "$DOROTHY/user/config.local/$load_dorothy_config__filename" | ||
load_dorothy_config__loaded='yes' | ||
elif test -f "$DOROTHY/user/config/$load_dorothy_config__filename"; then | ||
# load user/config/* | ||
. "$DOROTHY/user/config/$load_dorothy_config__filename" | ||
load_dorothy_config__loaded='yes' | ||
fi | ||
if test "$load_dorothy_config__only_first" = 'yes' -a "$load_dorothy_config__loaded" = 'yes'; then | ||
break | ||
fi | ||
done | ||
# if no user-defined configuration was provided, try the same filenames, but in the default configuration | ||
if test "$load_dorothy_config__loaded" = 'no'; then | ||
for load_dorothy_config__filename in "$@"; do | ||
if test -f "$DOROTHY/config/$load_dorothy_config__filename"; then | ||
# load default configuration | ||
. "$DOROTHY/config/$load_dorothy_config__filename" | ||
load_dorothy_config__loaded='yes' | ||
fi | ||
if test "$load_dorothy_config__only_first" = 'yes' -a "$load_dorothy_config__loaded" = 'yes'; then | ||
break | ||
fi | ||
done | ||
fi | ||
|
||
# if nothing was loaded, then fail | ||
if test "$dorothy_config_loaded" = 'no'; then | ||
echo-style --error="Missing the configuration file: $*" >/dev/stderr | ||
return 2 # ENOENT 2 No such file or directory | ||
if test "$load_dorothy_config__loaded" = 'no'; then | ||
if test "$load_dorothy_config__optional" = 'no'; then | ||
echo-style --error="Missing the configuration file: $*" >/dev/stderr | ||
return 2 # ENOENT 2 No such file or directory | ||
fi | ||
fi | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,54 @@ | ||
#!/usr/bin/env xonsh | ||
|
||
# @todo: couldn't get this going | ||
# @todo THIS IS UNUSED, AS COULD NOT GET IT WORKING AS INTENDED | ||
|
||
from os import path | ||
|
||
# for scripts and sources to load a configuration file | ||
# load_dorothy_config ...<filename> | ||
# load_dorothy_config [--first] [--silent] [--] ...<filename> | ||
def load_dorothy_config(*args): | ||
dorothy_config_loaded = False | ||
# process arguments | ||
only_first = False | ||
optional = False | ||
while len(args) > 0: | ||
if args[0] == '--first': | ||
args = args[1:] | ||
only_first = True | ||
elif args[0] == '--optional': | ||
args = args[1:] | ||
optional = True | ||
elif args[0] == '--': | ||
args = args[1:] | ||
break | ||
else: | ||
break | ||
|
||
# for each filename, load a single config file | ||
# load the configuration | ||
loaded = False | ||
# for each filename, try user/config.local otherwise user/config | ||
for filename in args: | ||
if path.exists($DOROTHY + '/user/config.local/' + filename): | ||
# load user/config.local/* | ||
execx(compilex(open($DOROTHY + '/user/config.local/' + filename).read())) | ||
dorothy_config_loaded = True | ||
loaded = True | ||
elif path.exists($DOROTHY + '/user/config/' + filename): | ||
# otherwise load user/config/* | ||
# load user/config/* | ||
execx(compilex(open($DOROTHY + '/user/config/' + filename).read())) | ||
dorothy_config_loaded = True | ||
elif path.exists($DOROTHY + '/config/' + filename): | ||
# otherwise load default configuration | ||
execx(compilex(open($DOROTHY + '/config/' + filename).read())) | ||
dorothy_config_loaded = True | ||
# otherwise try next filename | ||
loaded = True | ||
if only_first == 'yes' and loaded == 'yes': | ||
break | ||
# if no user-defined configuration was provided, try the same filenames, but in the default configuration | ||
if loaded == False: | ||
for filename in args: | ||
if path.exists($DOROTHY + '/config/' + filename): | ||
# load default configuration | ||
execx(compilex(open($DOROTHY + '/config/' + filename).read())) | ||
loaded = True | ||
if only_first == 'yes' and loaded == 'yes': | ||
break | ||
|
||
# if nothing was loaded, then fail | ||
if dorothy_config_loaded == False: | ||
echo-style --error=@('Missing the configuration file: ' + args.join(' ')) >/dev/stderr | ||
return 2 # No such file or directory | ||
if loaded == False: | ||
if optional == False: | ||
echo-style --error=@('Missing the configuration file: ' + args.join(' ')) >/dev/stderr | ||
return 2 # ENOENT 2 No such file or directory | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters