Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
galabovaa committed Mar 6, 2025
1 parent 79b6265 commit 3410dc8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
29 changes: 15 additions & 14 deletions app/CLI11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5014,10 +5014,10 @@ class FormatterBase {
///@{

/// The width of the left column (options/flags/subcommands)
std::size_t column_width_{30};
std::size_t column_width_{18};

/// The width of the right column (description of options/flags/subcommands)
std::size_t right_column_width_{65};
std::size_t right_column_width_{60};

/// The width of the description paragraph at the top of help
std::size_t description_paragraph_width_{80};
Expand Down Expand Up @@ -5207,7 +5207,7 @@ template <typename CRTP> class OptionBase {

protected:
/// The group membership
std::string group_ = std::string("OPTIONS");
std::string group_ = std::string("options");

/// True if this is a required option
bool required_{false};
Expand Down Expand Up @@ -6962,7 +6962,7 @@ class App {
/// Create a new program. Pass in the same arguments as main(), along with a help string.
explicit App(std::string app_description = "", std::string app_name = "")
: App(app_description, app_name, nullptr) {
set_help_flag("-h,--help", "Print help.");
// set_help_flag("-h,--help", "Print help.");
}

App(const App &) = delete;
Expand Down Expand Up @@ -10997,23 +10997,23 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,

std::vector<std::string> groups = app->get_groups();
bool defaultUsed = false;
groups.insert(groups.begin(), std::string("OPTIONS"));
groups.insert(groups.begin(), std::string("options"));

for(auto &group : groups) {
if(group == "OPTIONS" || group.empty()) {
if(group == "options" || group.empty()) {
if(defaultUsed) {
continue;
}
defaultUsed = true;
}
if(write_description && group != "OPTIONS" && !group.empty()) {
if(write_description && group != "options" && !group.empty()) {
out << '\n' << commentChar << commentLead << group << " Options\n";
}
for(const Option *opt : app->get_options({})) {
// Only process options that are configurable
if(opt->get_configurable()) {
if(opt->get_group() != group) {
if(!(group == "OPTIONS" && opt->get_group().empty())) {
if(!(group == "options" && opt->get_group().empty())) {
continue;
}
}
Expand Down Expand Up @@ -11168,7 +11168,7 @@ CLI11_INLINE std::string Formatter::make_positionals(const App *app) const {
if(opts.empty())
return {};

return make_group(get_label("POSITIONALS"), true, opts);
return make_group(get_label("positionals"), true, opts);
}

CLI11_INLINE std::string Formatter::make_groups(const App *app, AppFormatMode mode) const {
Expand Down Expand Up @@ -11241,7 +11241,7 @@ CLI11_INLINE std::string Formatter::make_usage(const App *app, std::string name)
std::vector<const Option *> non_pos_options =
app->get_options([](const Option *opt) { return opt->nonpositional(); });
if(!non_pos_options.empty())
out << " [" << get_label("OPTIONS") << "]";
out << " [" << get_label("options") << "]";

// Positionals need to be listed here
std::vector<const Option *> positionals = app->get_options([](const Option *opt) { return opt->get_positional(); });
Expand All @@ -11267,7 +11267,8 @@ CLI11_INLINE std::string Formatter::make_usage(const App *app, std::string name)
<< (app->get_require_subcommand_min() == 0 ? "]" : "");
}

out << "\n\n";
// out << "\n\n";
out << "\n";

return out.str();
}
Expand Down Expand Up @@ -11296,7 +11297,7 @@ CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name,
detail::streamOutAsParagraph(
out, make_description(app), description_paragraph_width_, ""); // Format description as paragraph
out << make_usage(app, name);
out << make_positionals(app);
// out << make_positionals(app);
out << make_groups(app, mode);
out << make_subcommands(app, mode);
detail::streamOutAsParagraph(out, make_footer(app), footer_paragraph_width_); // Format footer as paragraph
Expand Down Expand Up @@ -11414,9 +11415,9 @@ CLI11_INLINE std::string Formatter::make_option(const Option *opt, bool is_posit
std::string longNames = detail::join(vlongNames, ", ");

// Calculate setw sizes
const auto shortNamesColumnWidth = static_cast<int>(column_width_ / 3); // 33% left for short names
const auto shortNamesColumnWidth = static_cast<int>(column_width_ / 5); // 20% left for short names
const auto longNamesColumnWidth = static_cast<int>(std::ceil(
static_cast<float>(column_width_) / 3.0f * 2.0f)); // 66% right for long names and options, ceil result
static_cast<float>(column_width_) / 5.0f * 4.0f)); // 80% right for long names and options, ceil result
int shortNamesOverSize = 0;

// Print short names
Expand Down
42 changes: 28 additions & 14 deletions app/HighsRuntimeOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ struct HighsCommandLineOptions {
void setupCommandLineOptions(CLI::App& app,
HighsCommandLineOptions& cmd_options) {

// Version.
app.add_flag("--version,-v", cmd_options.cmd_version, " Print version.");

// Command line file specifications.
app.add_option("--" + kModelFileString + "," + kModelFileString,
Expand Down Expand Up @@ -82,23 +80,32 @@ void setupCommandLineOptions(CLI::App& app,
// Command line option specifications.
app.add_option(
"--" + kPresolveString, cmd_options.cmd_presolve,
"Presolve: \"choose\" by default - \"on\"/\"off\" are alternatives.");
"Set presolve to:\n"
" \"choose\" * default\n"
" \"on\"\n"
" \"off\"");
// "Presolve: \"choose\" by default - \"on\"/\"off\" \nare alternatives.");

app.add_option("--" + kSolverString, cmd_options.cmd_solver,
// "Solver: \"choose\" by default - \n\"simplex\"/\"ipm\" are "
" Solver: \"choose\" by default - \"simplex\"/\"ipm\" are "
"alternatives.");
"Set solver to:\n"
" \"choose\" * default\n"
" \"simplex\"\n"
" \"ipm\"");

app.add_option("--" + kParallelString, cmd_options.cmd_parallel,
// "Parallel solve: \"choose\" by default - \n\"on\"/\"off\" are "
" Parallel solve: \"choose\" by default - \"on\"/\"off\" are "
"alternatives.");
"Set parallel to:\n"
" \"choose\" * default\n"
" \"on\"\n"
" \"off\"");

app.add_option("--" + kRunCrossoverString, cmd_options.cmd_crossover,
// "Run crossover: \"on\" by default - \n\"choose\"/\"off\" are "
" Run crossover: \"on\" by default - \"choose\"/\"off\" are "
"alternatives.");
"Set run crossover to:\n"
" \"choose\"\n"
" \"on\" * default\n"
" \"off\"");

app.add_option("--" + kTimeLimitString, cmd_options.cmd_time_limit,
"Run time limit (seconds - double).");
Expand Down Expand Up @@ -127,18 +134,25 @@ void setupCommandLineOptions(CLI::App& app,
"Seed to initialize random number \ngeneration.");

app.add_option("--" + kRangingString, cmd_options.cmd_ranging,
"Compute cost, bound, RHS and basic solution ranging.");
"Compute cost, bound, RHS and basic \nsolution ranging:\n"
" \"on\"\n"
" \"off\" * default");
// "Compute cost, bound, RHS and basic solution \nranging.");

// app.set_version_flag("--version", getVersionString());

// Version.
app.add_flag("--version,-v", cmd_options.cmd_version, " Print version.");
app.set_help_flag("-h,--help", "Print help.");

app.get_formatter()->column_width(33);
app.get_formatter()->label("TEXT:FILE", "arg");
app.get_formatter()->label("TEXT", "arg");
app.get_formatter()->label("FLOAT", "double");

app.get_formatter()->label("TEXT:FILE", "file");
app.get_formatter()->label("TEXT", "text");
app.get_formatter()->label("FLOAT", "float");
app.get_formatter()->label("INT", "int");
app.get_formatter()->label("OPTIONS", "options");
app.get_formatter()->label("POSITIONALS", "positionals");

}

bool loadOptions(const CLI::App& app, const HighsLogOptions& report_log_options,
Expand Down
6 changes: 4 additions & 2 deletions app/RunHighs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int main(int argc, char** argv) {
// cxxopts now Cpp17 with
// CLI11 for Cpp11

CLI::App app{"HiGHS command line options"};
CLI::App app{"HiGHS"};
argv = app.ensure_utf8(argv);

setupCommandLineOptions(app, cmd_options);
Expand All @@ -52,12 +52,14 @@ int main(int argc, char** argv) {
// app.help();
// return 0;
// }
std::string usage_msg = "usage: \n " + std::string(argv[0]) + " [option...] [file]";
app.usage(usage_msg);

app.parse(argc, argv);
}
// Catch call for help.
catch (const CLI::CallForHelp& e) {
std::cout << app.help();
std::cout << app.help() << std::endl;
return 0;
}
catch (const CLI::CallForAllHelp& e) {
Expand Down

0 comments on commit 3410dc8

Please sign in to comment.