|
31 | 31 |
|
32 | 32 | #include <cloe/utility/std_extensions.hpp> // for split_string
|
33 | 33 | #include <cloe/utility/xdg.hpp> // for merge_config
|
| 34 | +#include <fable/environment.hpp> // for Environment |
34 | 35 | #include <fable/utility.hpp> // for pretty_print, read_conf_from_file
|
35 | 36 |
|
36 | 37 | #include "plugins/nop_controller.hpp" // for NopFactory
|
|
41 | 42 |
|
42 | 43 | namespace cloe {
|
43 | 44 |
|
| 45 | +Conf read_conf(const StackOptions& opt, const std::string& filepath) { |
| 46 | + if (!opt.interpolate_vars) { |
| 47 | + return fable::read_conf(filepath); |
| 48 | + } |
| 49 | + |
| 50 | + // Prepare environment with extra variables: |
| 51 | + fable::Environment env(*opt.environment); |
| 52 | + if (!filepath.empty() && filepath != "-") { |
| 53 | + std::string dirpath = boost::filesystem::canonical(filepath).parent_path().native(); |
| 54 | + env.set("THIS_STACKFILE_FILE", filepath); |
| 55 | + env.set("THIS_STACKFILE_DIR", dirpath); |
| 56 | + } |
| 57 | + return fable::read_conf_with_interpolation(filepath, &env); |
| 58 | +} |
| 59 | + |
44 | 60 | void merge_stack(const StackOptions& opt, Stack& s, const std::string& filepath) {
|
45 | 61 | auto merge = [&]() {
|
46 |
| - Conf c; |
47 |
| - if (opt.interpolate_vars) { |
48 |
| - c = fable::read_conf_with_interpolation(filepath, opt.environment.get()); |
49 |
| - } else { |
50 |
| - c = fable::read_conf(filepath); |
51 |
| - } |
| 62 | + Conf c = read_conf(opt, filepath); |
52 | 63 |
|
53 | 64 | if (opt.no_hooks) {
|
54 | 65 | // Removing hooks from the config allows the stack to validate even if
|
@@ -95,9 +106,8 @@ Stack new_stack(const StackOptions& opt) {
|
95 | 106 | };
|
96 | 107 | interpolate_path(s.engine.registry_path);
|
97 | 108 | interpolate_path(s.engine.output_path);
|
98 |
| - s.set_conf_reader([&opt](const std::string& filepath) -> cloe::Conf { |
99 |
| - return fable::read_conf_with_interpolation(filepath, opt.environment.get()); |
100 |
| - }); |
| 109 | + s.set_conf_reader( |
| 110 | + [&opt](const std::string& filepath) -> cloe::Conf { return read_conf(opt, filepath); }); |
101 | 111 | }
|
102 | 112 |
|
103 | 113 | // Insert ignored sections
|
|
0 commit comments