Skip to content

Commit

Permalink
feat: Add run arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsheep committed Jul 20, 2020
1 parent 649e91a commit 4b41d9a
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ int main(int argc, char **argv)
CLI::App app{"App description"};

Options options;
std::string run_options;

CLI::App *build = app.add_subcommand("build", "Build sources");
build->add_option("ENTRY", options.entry_file, "Entry file")->required()->check(CLI::ExistingFile);
Expand Down Expand Up @@ -253,11 +254,48 @@ int main(int argc, char **argv)
}
else
{
std::system((options.output_file).c_str());
std::system((options.output_file + run_options).c_str());
}
});

CLI11_PARSE(app, argc, argv);
std::vector<char *> args;
bool is_run_option = false;

for (auto i = 0; i < argc; i++)
{
if (is_run_option)
{
std::stringstream ss;
ss << '"';

for (auto &c : std::string(argv[i]))
{
if (c == '"' || c == '\\')
{
ss << '\\';
ss << c;
}
else
{
ss << c;
}
}

ss << '"';

run_options += ' ' + ss.str();
}
else if (std::strcmp(argv[i], "--") == 0)
{
is_run_option = true;
}
else
{
args.push_back(argv[i]);
}
}

CLI11_PARSE(app, args.size(), &args[0]);

return 0;
}

0 comments on commit 4b41d9a

Please sign in to comment.