24 |
24 |
25 class CLIParser { |
25 class CLIParser { |
26 private: |
26 private: |
27 |
27 |
28 static const std::string OPTION_TEXTURE; |
28 static const std::string OPTION_TEXTURE; |
|
29 static const std::string OPTION_SHADER; |
29 static const std::string OPTION_BACKGROUND_COLOR; |
30 static const std::string OPTION_BACKGROUND_COLOR; |
30 static const std::string OPTION_ROOT_WINDOW; |
31 static const std::string OPTION_ROOT_WINDOW; |
31 |
32 |
32 const std::string |
33 const std::string |
33 readNext(const std::vector<std::string>& arguments, int& i) { |
34 readNext(const std::vector<std::string>& arguments, int& i) { |
68 |
69 |
69 if (option == OPTION_TEXTURE) { |
70 if (option == OPTION_TEXTURE) { |
70 Configuration::Texture tex; |
71 Configuration::Texture tex; |
71 tex.fileName = readNext(arguments, i); |
72 tex.fileName = readNext(arguments, i); |
72 c.textures.push_back(tex); |
73 c.textures.push_back(tex); |
|
74 } else if (option == OPTION_SHADER) { |
|
75 const auto type = readNext(arguments, i); |
|
76 const auto file = readNext(arguments, i); |
|
77 if (type == "fragment") c.fragmentShaders.push_back({file}); |
|
78 else if (type == "vertex") c.vertexShaders .push_back({file}); |
|
79 else throw std::invalid_argument("unsupported shader type"); |
73 } else if (option == OPTION_BACKGROUND_COLOR) { |
80 } else if (option == OPTION_BACKGROUND_COLOR) { |
74 c.backgroundColor = parseHexColor(readNext(arguments, i)); |
81 c.backgroundColor = parseHexColor(readNext(arguments, i)); |
75 } else if (option == OPTION_ROOT_WINDOW) { |
82 } else if (option == OPTION_ROOT_WINDOW) { |
76 c.rootWindow = std::stoul(readNext(arguments, i)); |
83 c.rootWindow = std::stoul(readNext(arguments, i)); |
77 } else throw std::logic_error("Unsupported CLI option: " + option); |
84 } else throw std::logic_error("Unsupported CLI option: " + option); |