Fix handling of base directory
Prior to this patch, Dotbot was relying on running with the base directory being the current working directory. In practice, it was relying on the install shim to set up this context. It makes more sense sense to actually execute `chdir()` within Dotbot itself, rather than relying on the install shim to do so.
This commit is contained in:
parent
2f4cc0d9cb
commit
c3f271481a
|
@ -14,10 +14,10 @@ def add_options(parser):
|
||||||
help='suppress most output')
|
help='suppress most output')
|
||||||
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
|
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
|
||||||
help='enable verbose output')
|
help='enable verbose output')
|
||||||
parser.add_argument('-d', '--base-directory', nargs=1,
|
parser.add_argument('-d', '--base-directory',
|
||||||
dest='base_directory', help='execute commands from within BASEDIR',
|
dest='base_directory', help='execute commands from within BASEDIR',
|
||||||
metavar='BASEDIR', required=True)
|
metavar='BASEDIR', required=True)
|
||||||
parser.add_argument('-c', '--config-file', nargs=1, dest='config_file',
|
parser.add_argument('-c', '--config-file', dest='config_file',
|
||||||
help='run commands given in CONFIGFILE', metavar='CONFIGFILE',
|
help='run commands given in CONFIGFILE', metavar='CONFIGFILE',
|
||||||
required=True)
|
required=True)
|
||||||
parser.add_argument('-p', '--plugin', action='append', dest='plugins', default=[],
|
parser.add_argument('-p', '--plugin', action='append', dest='plugins', default=[],
|
||||||
|
@ -55,10 +55,11 @@ def main():
|
||||||
for plugin_path in plugin_paths:
|
for plugin_path in plugin_paths:
|
||||||
abspath = os.path.abspath(plugin_path)
|
abspath = os.path.abspath(plugin_path)
|
||||||
module.load(abspath)
|
module.load(abspath)
|
||||||
tasks = read_config(options.config_file[0])
|
tasks = read_config(options.config_file)
|
||||||
if not isinstance(tasks, list):
|
if not isinstance(tasks, list):
|
||||||
raise ReadingError('Configuration file must be a list of tasks')
|
raise ReadingError('Configuration file must be a list of tasks')
|
||||||
dispatcher = Dispatcher(options.base_directory[0])
|
os.chdir(options.base_directory)
|
||||||
|
dispatcher = Dispatcher(options.base_directory)
|
||||||
success = dispatcher.dispatch(tasks)
|
success = dispatcher.dispatch(tasks)
|
||||||
if success:
|
if success:
|
||||||
log.info('\n==> All tasks executed successfully')
|
log.info('\n==> All tasks executed successfully')
|
||||||
|
|
|
@ -51,17 +51,15 @@ initialize() {
|
||||||
|
|
||||||
run_dotbot() {
|
run_dotbot() {
|
||||||
(
|
(
|
||||||
cd "${DOTFILES}"
|
cat > "${DOTFILES}/${INSTALL_CONF}"
|
||||||
cat > "${INSTALL_CONF}"
|
${DOTBOT_EXEC} -d "${DOTFILES}" -c "${DOTFILES}/${INSTALL_CONF}" "${@}"
|
||||||
${DOTBOT_EXEC} -d . -c "${INSTALL_CONF}" "${@}"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
run_dotbot_json() {
|
run_dotbot_json() {
|
||||||
(
|
(
|
||||||
cd "${DOTFILES}"
|
cat > "${DOTFILES}/${INSTALL_CONF_JSON}"
|
||||||
cat > "${INSTALL_CONF_JSON}"
|
${DOTBOT_EXEC} -d "${DOTFILES}" -c "${DOTFILES}/${INSTALL_CONF_JSON}" "${@}"
|
||||||
${DOTBOT_EXEC} -d . -c "${INSTALL_CONF_JSON}" "${@}"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'run' '
|
test_expect_success 'run' '
|
||||||
run_dotbot --plugin-dir plugins <<EOF
|
run_dotbot --plugin-dir ${DOTFILES}/plugins <<EOF
|
||||||
- test: ~
|
- test: ~
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
|
@ -18,7 +18,7 @@ EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'run' '
|
test_expect_success 'run' '
|
||||||
run_dotbot --plugin test.py <<EOF
|
run_dotbot --plugin ${DOTFILES}/test.py <<EOF
|
||||||
- test: ~
|
- test: ~
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
Loading…
Reference in a new issue