summaryrefslogtreecommitdiff
path: root/tools/hscript-simulate/simulator.cc
diff options
context:
space:
mode:
authorCalvin Buckley <calvin@cmpct.info>2020-02-11 18:24:37 -0400
committerCalvin Buckley <calvin@cmpct.info>2020-02-11 18:32:26 -0400
commit4946a64db774a140d06c45f186f5bc5a4c0c6daa (patch)
treeebd08b88588ca8390842be86209129e58efd9f25 /tools/hscript-simulate/simulator.cc
parent9fa9857a7514469d062335cd2dcb8c0d06eb624c (diff)
downloadhorizon-4946a64db774a140d06c45f186f5bc5a4c0c6daa.tar.gz
horizon-4946a64db774a140d06c45f186f5bc5a4c0c6daa.tar.bz2
horizon-4946a64db774a140d06c45f186f5bc5a4c0c6daa.tar.xz
horizon-4946a64db774a140d06c45f186f5bc5a4c0c6daa.zip
Use Boost's program_options instead of vendoring clipp
This changes how options are parsed a bit, but tests are happy and typical usage is unaffected; just the usage screen is different. This was intended for post-1.0, but turns out I decided to do it. Boost is already required for pre-C++11, so it doesn't seem like a big deal to use. If you don't build the tools, it won't be required.
Diffstat (limited to 'tools/hscript-simulate/simulator.cc')
-rw-r--r--tools/hscript-simulate/simulator.cc57
1 files changed, 43 insertions, 14 deletions
diff --git a/tools/hscript-simulate/simulator.cc b/tools/hscript-simulate/simulator.cc
index 3dd6175..7162c4b 100644
--- a/tools/hscript-simulate/simulator.cc
+++ b/tools/hscript-simulate/simulator.cc
@@ -9,13 +9,18 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
+#include <boost/program_options.hpp>
#include <unistd.h>
#include "hscript/script.hh"
#include "util/output.hh"
-#include "3rdparty/clipp.h"
bool pretty = false;
+static int cli_failure(boost::program_options::options_description cli) {
+ std::cout << cli << std::endl;
+ return EXIT_FAILURE;
+}
+
int main(int argc, char *argv[]) {
const Horizon::Script *my_script;
Horizon::ScriptOptions opts;
@@ -30,19 +35,43 @@ int main(int argc, char *argv[]) {
opts.set(ScriptOptionFlags::Simulate);
- auto cli = (
- clipp::value("installfile", installfile),
- clipp::option("-n", "--no-colour").doc("Do not 'prettify' output")(
- [] { pretty = false; }
- ),
- clipp::option("-s", "--strict").doc("Strict parsing")(
- [&opts] { opts.set(ScriptOptionFlags::StrictMode); }
- )
- );
- if(!clipp::parse(argc, argv, cli)) {
- std::cout << "usage:" << std::endl;
- std::cout << clipp::usage_lines(cli, "hscript-simulate") << std::endl;
- return EXIT_FAILURE;
+ boost::program_options::options_description cli_hidden;
+ cli_hidden.add_options()
+ ("installfile", "Installfile to load");
+ boost::program_options::options_description cli_visible("Allowed options");
+ cli_visible.add_options()
+ ("no-colour,n", "Do not 'prettify' output")
+ ("strict,s", "Strict parsing");
+ boost::program_options::options_description cli;
+ cli.add(cli_visible).add(cli_hidden);
+ boost::program_options::positional_options_description cli_pos;
+ cli_pos.add("installfile", -1);
+ boost::program_options::variables_map args;
+ try {
+ boost::program_options::store(
+ boost::program_options::command_line_parser(argc, argv)
+ .options(cli)
+ .positional(cli_pos)
+ .run(),
+ args);
+ boost::program_options::notify(args);
+ } catch(const boost::program_options::error& cli_err) {
+ std::cout << "An invalid option was entered." << std::endl;
+ return cli_failure(cli_visible);
+ }
+
+ if (args.count("installfile")) {
+ installfile = args["installfile"].as<std::string>();
+ } else {
+ std::cout << "You must provide an installfile." << std::endl;
+ return cli_failure(cli_visible);
+ }
+
+ if (args.count("no-colour")) {
+ pretty = false;
+ }
+ if (args.count("strict")) {
+ opts.set(ScriptOptionFlags::StrictMode);
}
if(!isatty(1)) {