Skip to content

Commit a6c5f03

Browse files
committed
Merge branch 'alipatti/master'
2 parents 60cbaf6 + 1bc9fb5 commit a6c5f03

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

src/dotbot/cli.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import sys
55
from argparse import ArgumentParser, RawTextHelpFormatter
6-
from typing import Any
6+
from typing import Any, List
77

88
import dotbot
99
from dotbot.config import ConfigReader, ReadingError
@@ -23,8 +23,10 @@ def add_options(parser: ArgumentParser) -> None:
2323
default=0,
2424
help="enable verbose output\n" "-v: typical verbose\n" "-vv: also, set shell commands stderr/stdout to true",
2525
)
26-
parser.add_argument("-d", "--base-directory", help="execute commands from within BASEDIR", metavar="BASEDIR")
27-
parser.add_argument("-c", "--config-file", help="run commands given in CONFIGFILE", metavar="CONFIGFILE")
26+
parser.add_argument("-d", "--base-directory", help="execute commands from within BASE_DIR", metavar="BASE_DIR")
27+
parser.add_argument(
28+
"-c", "--config-file", help="run commands given in CONFIG_FILE", metavar="CONFIG_FILE", nargs="+"
29+
)
2830
parser.add_argument(
2931
"-p",
3032
"--plugin",
@@ -57,8 +59,8 @@ def add_options(parser: ArgumentParser) -> None:
5759
)
5860

5961

60-
def read_config(config_file: str) -> Any:
61-
reader = ConfigReader(config_file)
62+
def read_config(config_files: List[str]) -> Any:
63+
reader = ConfigReader(config_files)
6264
return reader.get_config()
6365

6466

@@ -118,17 +120,13 @@ def main() -> None:
118120
log.error("No configuration file specified")
119121
sys.exit(1)
120122
tasks = read_config(options.config_file)
121-
if tasks is None:
122-
log.warning("Configuration file is empty, no work to do")
123-
tasks = []
124-
if not isinstance(tasks, list):
125-
msg = "Configuration file must be a list of tasks"
126-
raise ReadingError(msg) # noqa: TRY301
123+
if not tasks:
124+
log.warning("No tasks given in configuration, no work to do")
127125
if options.base_directory:
128126
base_directory = os.path.abspath(options.base_directory)
129127
else:
130-
# default to directory of config file
131-
base_directory = os.path.dirname(os.path.abspath(options.config_file))
128+
# default to directory of first config file
129+
base_directory = os.path.dirname(os.path.abspath(options.config_file[0]))
132130
os.chdir(base_directory)
133131
_all_plugins[:] = plugins # for backwards compatibility, see dispatcher.py
134132
dispatcher = Dispatcher(

src/dotbot/config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import json
22
import os.path
3-
from typing import Any
3+
from typing import Any, List
44

55
import yaml
66

77
from dotbot.util import string
88

99

1010
class ConfigReader:
11-
def __init__(self, config_file_path: str):
12-
self._config = self._read(config_file_path)
11+
_config: List[Any]
12+
13+
def __init__(self, config_file_paths: List[str]):
14+
self._config = []
15+
for path in config_file_paths:
16+
config = self._read(path)
17+
if config is None:
18+
continue
19+
if not isinstance(config, list):
20+
msg = "Configuration file must be a list of tasks"
21+
raise ReadingError(msg)
22+
self._config.extend(config)
1323

1424
def _read(self, config_file_path: str) -> Any:
1525
try:

tests/test_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,20 @@ def test_json_tabs(home: str, dotfiles: Dotfiles, run_dotbot: Callable[..., None
3737
run_dotbot("-c", os.path.join(dotfiles.directory, "config.json"), custom=True)
3838

3939
assert os.path.isdir(os.path.join(home, "d"))
40+
41+
42+
def test_multiple_config(home: str, dotfiles: Dotfiles, run_dotbot: Callable[..., None]) -> None:
43+
"""Verify that passing multiple configs works."""
44+
45+
dotfiles.write("config1.json", json.dumps([{"create": ["~/d1"]}]))
46+
dotfiles.write("config2.json", json.dumps([{"create": ["~/d2"]}]))
47+
48+
run_dotbot(
49+
"-c",
50+
os.path.join(dotfiles.directory, "config1.json"),
51+
os.path.join(dotfiles.directory, "config2.json"),
52+
custom=True,
53+
)
54+
55+
assert os.path.isdir(os.path.join(home, "d1"))
56+
assert os.path.isdir(os.path.join(home, "d2"))

0 commit comments

Comments
 (0)