Use standard library JSON parser for JSON files
This patch reverts the changes to the README made in
57265f78b4
and makes it so that Dotbot
supports JSON files with tab characters.
This commit is contained in:
parent
9250bef422
commit
c48d16cbce
5 changed files with 63 additions and 8 deletions
10
README.md
10
README.md
|
@ -118,13 +118,9 @@ Configuration
|
|||
-------------
|
||||
|
||||
Dotbot uses YAML or JSON formatted configuration files to let you specify how
|
||||
to set up your dotfiles. The YAML format is recommended because it looks
|
||||
cleaner. JSON will be parsed as a subset of YAML, so tab characters are not
|
||||
permitted.
|
||||
|
||||
Currently, Dotbot knows how to [link](#link) files and folders, execute
|
||||
[shell](#shell) commands, and [clean](#clean) directories of broken symbolic
|
||||
links.
|
||||
to set up your dotfiles. Currently, Dotbot knows how to [link](#link) files and
|
||||
folders, execute [shell](#shell) commands, and [clean](#clean) directories of
|
||||
broken symbolic links.
|
||||
|
||||
**Ideally, bootstrap configurations should be idempotent. That is, the
|
||||
installer should be able to be run multiple times without causing any
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import yaml
|
||||
import json
|
||||
from .util import string
|
||||
|
||||
class ConfigReader(object):
|
||||
|
@ -8,7 +9,16 @@ class ConfigReader(object):
|
|||
def _read(self, config_file_path):
|
||||
try:
|
||||
with open(config_file_path) as fin:
|
||||
try:
|
||||
data = yaml.safe_load(fin)
|
||||
except Exception as e:
|
||||
# try falling back to JSON, but return original exception
|
||||
# if that fails too
|
||||
try:
|
||||
fin.seek(0)
|
||||
data = json.load(fin)
|
||||
except Exception:
|
||||
raise e
|
||||
return data
|
||||
except Exception as e:
|
||||
msg = string.indent_lines(str(e))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
DEBUG=false
|
||||
DOTFILES='/home/vagrant/dotfiles'
|
||||
INSTALL_CONF='install.conf.yaml'
|
||||
INSTALL_CONF_JSON='install.conf.json'
|
||||
|
||||
test_run_() {
|
||||
if ! ${DEBUG}; then
|
||||
|
@ -48,4 +49,12 @@ run_dotbot() {
|
|||
)
|
||||
}
|
||||
|
||||
run_dotbot_json() {
|
||||
(
|
||||
cd "${DOTFILES}"
|
||||
cat > "${INSTALL_CONF_JSON}"
|
||||
/dotbot/bin/dotbot -d . -c "${INSTALL_CONF_JSON}" "${@}"
|
||||
)
|
||||
}
|
||||
|
||||
initialize
|
||||
|
|
20
test/tests/config-json-tabs.bash
Normal file
20
test/tests/config-json-tabs.bash
Normal file
|
@ -0,0 +1,20 @@
|
|||
test_description='json config with tabs allowed'
|
||||
. '../test-lib.bash'
|
||||
|
||||
test_expect_success 'setup' '
|
||||
echo "grape" > ${DOTFILES}/h
|
||||
'
|
||||
|
||||
test_expect_success 'run' '
|
||||
run_dotbot_json <<EOF
|
||||
[{
|
||||
"link": {
|
||||
"~/.i": "h"
|
||||
}
|
||||
}]
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'test' '
|
||||
grep "grape" ~/.i
|
||||
'
|
20
test/tests/config-json.bash
Normal file
20
test/tests/config-json.bash
Normal file
|
@ -0,0 +1,20 @@
|
|||
test_description='json config allowed'
|
||||
. '../test-lib.bash'
|
||||
|
||||
test_expect_success 'setup' '
|
||||
echo "grape" > ${DOTFILES}/h
|
||||
'
|
||||
|
||||
test_expect_success 'run' '
|
||||
run_dotbot_json <<EOF
|
||||
[{
|
||||
"link": {
|
||||
"~/.i": "h"
|
||||
}
|
||||
}]
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success 'test' '
|
||||
grep "grape" ~/.i
|
||||
'
|
Loading…
Reference in a new issue