Refined documentation of command line parser and buddies.

This commit is contained in:
Matthias Koefferlein 2017-08-15 00:13:57 +02:00
parent 492351519e
commit 9f8144a254
2 changed files with 31 additions and 11 deletions

View File

@ -34,17 +34,18 @@ main (int argc, char *argv [])
tl::CommandLineOptions cmd;
cmd << tl::arg ("-ov|--max-vertex-count=count", &gds2_options.max_vertex_count, "Specify the maximum number of points per polygon",
cmd << tl::arg ("-ov|--max-vertex-count=count", &gds2_options.max_vertex_count, "Specifies the maximum number of points per polygon",
"If this number is given, polygons are cut into smaller parts if they have more "
"than the specified number of points. If not given, the maximum number of points will be used. "
"This is 8190 unless --multi-xy-records is given."
)
<< tl::arg ("-om|--multi-xy-records", &gds2_options.multi_xy_records, "Allow unlimited number of points",
<< tl::arg ("-om|--multi-xy-records", &gds2_options.multi_xy_records, "Allows unlimited number of points",
"If this option is given, multiple XY records will be written to accomodate an unlimited number "
"of points per polygon or path. However, such files may not be compatible with some consumers."
)
<< tl::arg ("-oz|--no-zero-length-paths", &gds2_options.no_zero_length_paths, "Don't allow zero-length paths",
"If this option is given, zero-length paths (such with one point) are not written."
<< tl::arg ("-oz|--no-zero-length-paths", &gds2_options.no_zero_length_paths, "Converts zero-length paths to polygons",
"If this option is given, zero-length paths (such with one point) are not written as paths "
"but converted to polygons. This avoids compatibility issues with consumers of this layout file."
)
<< tl::arg ("-on|--cellname-length=length", &gds2_options.max_cellname_length, "Limits cell names to the given length",
"If this option is given, long cell names will truncated if their length exceeds the given length."
@ -119,15 +120,16 @@ main (int argc, char *argv [])
writer.write (layout, stream, save_options);
}
} catch (tl::CancelException &ex) {
return 1;
} catch (std::exception &ex) {
fprintf (stderr, "*** ERROR: %s\n", ex.what ());
tl::error << ex.what ();
return 1;
} catch (tl::Exception &ex) {
fprintf (stderr, "*** ERROR: %s\n", ex.msg ().c_str ());
tl::error << ex.msg ();
return 1;
} catch (...) {
fprintf (stderr, "*** ERROR: unspecific error\n");
return 1;
tl::error << "ERROR: unspecific error";
}
return 0;

View File

@ -168,7 +168,7 @@ CommandLineOptions::produce_help (const std::string &program_name)
tl::info << " " << program_name << " [options]" << tl::noendl;
for (std::vector<ArgBase *>::const_iterator a = m_args.begin (); a != m_args.end (); ++a) {
if (! (*a)->option ().name.empty ()) {
if (! (*a)->is_option ()) {
if ((*a)->option ().optional) {
tl::info << " [<" << (*a)->option ().name << ">]" << tl::noendl;
} else {
@ -213,6 +213,24 @@ CommandLineOptions::produce_help (const std::string &program_name)
tl::info << "";
tl::info << "Options:" << tl::endl;
print_string_formatted (" ", columns,
"Options can be specified in a short (with one dash) or a long form "
"(with two dashes). If a value is required, it can be specified either "
"as the following argument or added to the option with an equal sign (=).");
tl::info << tl::endl << " Examples:" << tl::endl << tl::endl
<< " -a 1" << tl::endl
<< " -a=1" << tl::endl
<< " --long 1" << tl::endl
<< " --long=1" << tl::endl;
tl::info << " List of options:" << tl::endl;
tl::info << " "
<< pad_string (short_option_width + 5, "Short") << " "
<< pad_string (long_option_width + 5, "Long") << " "
<< pad_string (name_width + 3, "Value") << " " << "Description" << tl::endl;
for (std::vector<ArgBase *>::const_iterator a = m_args.begin (); a != m_args.end (); ++a) {
if (! (*a)->is_option ()) {
continue;
@ -224,7 +242,7 @@ CommandLineOptions::produce_help (const std::string &program_name)
name = "value";
}
}
tl::info << " "
tl::info << " "
<< pad_string (short_option_width + 5, (*a)->option ().short_option.empty () ? "" : "-" + (*a)->option ().short_option) << " "
<< pad_string (long_option_width + 5, (*a)->option ().long_option.empty () ? "" : "--" + (*a)->option ().long_option) << " "
<< pad_string (name_width + 3, name) << " "
@ -232,7 +250,7 @@ CommandLineOptions::produce_help (const std::string &program_name)
tl::info << "";
if (! (*a)->long_doc ().empty ()) {
print_string_formatted (" ", columns, (*a)->long_doc ());
print_string_formatted (" ", columns, (*a)->long_doc ());
tl::info << "";
}
}