Commit 70587c3a55c1f507b1b754d15d9a5f3266685b75

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent 76f1b7bd

Moving to_flag to base class

Showing 1 changed file with 19 additions and 21 deletions
include/CLI/ConfigFwd.hpp
... ... @@ -70,27 +70,7 @@ class Config {
70 70 virtual std::vector<ConfigItem> from_config(std::istream &) const = 0;
71 71  
72 72 /// Convert a flag to a bool
73   - virtual std::vector<std::string> to_flag(const ConfigItem &) const = 0;
74   -
75   - /// Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure
76   - std::vector<ConfigItem> from_file(const std::string &name) {
77   - std::ifstream input{name};
78   - if(!input.good())
79   - throw FileError::Missing(name);
80   -
81   - return from_config(input);
82   - }
83   -
84   - /// virtual destructor
85   - virtual ~Config() = default;
86   -};
87   -
88   -/// This converter works with INI files
89   -class ConfigINI : public Config {
90   - public:
91   - std::string to_config(const App *, bool default_also, bool write_description, std::string prefix) const override;
92   -
93   - std::vector<std::string> to_flag(const ConfigItem &item) const override {
  73 + virtual std::vector<std::string> to_flag(const ConfigItem &item) const {
94 74 if(item.inputs.size() == 1) {
95 75 std::string val = item.inputs.at(0);
96 76 val = detail::to_lower(val);
... ... @@ -112,6 +92,24 @@ class ConfigINI : public Config {
112 92 }
113 93 }
114 94  
  95 + /// Parse a config file, throw an error (ParseError:ConfigParseError or FileError) on failure
  96 + std::vector<ConfigItem> from_file(const std::string &name) {
  97 + std::ifstream input{name};
  98 + if(!input.good())
  99 + throw FileError::Missing(name);
  100 +
  101 + return from_config(input);
  102 + }
  103 +
  104 + /// virtual destructor
  105 + virtual ~Config() = default;
  106 +};
  107 +
  108 +/// This converter works with INI files
  109 +class ConfigINI : public Config {
  110 + public:
  111 + std::string to_config(const App *, bool default_also, bool write_description, std::string prefix) const override;
  112 +
115 113 std::vector<ConfigItem> from_config(std::istream &input) const override {
116 114 std::string line;
117 115 std::string section = "default";
... ...