Skip to content

Commit f9a3b04

Browse files
committed
improved -help action
Signed-off-by: Ken Museth <ken.museth@gmail.com>
1 parent ec6abbe commit f9a3b04

4 files changed

Lines changed: 53 additions & 2 deletions

File tree

openvdb_cmd/vdb_tool/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,19 @@ vdb_tool -help
563563
vdb_tool -help read write
564564
```
565565

566+
## Searching for an action by keyword
567+
Lists every action whose name or documentation contains the (case-insensitive) keyword, so you can discover the right action without scrolling the full help. Add `brief=true` for a compact, one-line-per-action listing.
568+
```
569+
vdb_tool -help search=mesh
570+
```
571+
572+
## Did-you-mean suggestions for mistyped actions
573+
A mistyped action name &mdash; whether invoked directly or queried via `-help` &mdash; reports the closest known names instead of just failing:
574+
```
575+
vdb_tool -help mesh2sl # -> Did you mean: "-mesh2ls" or "-mesh2sdf"?
576+
vdb_tool -sphre # -> Did you mean: "-sphere"?
577+
```
578+
566579
## Getting help on all actions
567580
```
568581
vdb_tool -eval help="*"

openvdb_cmd/vdb_tool/include/Parser.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,22 @@ void Parser::usage(const VecS &actions, bool brief) const
17121712
{
17131713
for (const std::string &str : actions) {
17141714
auto search = hashMap.find(str);
1715-
if (search == hashMap.end()) throw std::invalid_argument(iter->names[0]+": Parser:::usage: unsupported action \""+str+"\"\n");
1715+
if (search == hashMap.end()) {
1716+
// Mirror the "Did you mean ...?" suggestion the parser gives for a
1717+
// mistyped action on the command line, so "-help sphre" is as
1718+
// helpful as "-sphre".
1719+
// No action prefix here: the only caller (Tool::help) already
1720+
// prepends "help: " in its catch handler.
1721+
std::stringstream ss;
1722+
ss << "unsupported action \"" << str << "\"";
1723+
auto matches = this->closeMatches(str);
1724+
for (auto it = matches.begin(); it != matches.end();) {
1725+
ss << "\nDid you mean: \"-" << (it++)->second << "\"";
1726+
while (it != matches.end()) ss << " or \"-" << (it++)->second << "\"";
1727+
ss << "?";
1728+
}
1729+
throw std::invalid_argument(ss.str());
1730+
}
17161731
std::clog << this->usage(*search->second, brief);
17171732
}
17181733
}// Parser::usage

openvdb_cmd/vdb_tool/include/Tool.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ void Tool::init()
597597
{{"actions", "", "read,write,...", "list of actions to document. If the list is empty documentation is printed for all available actions and if other actions proceed this action, documentation is printed for those actions only"},
598598
{"exit", "true", "1|0|true|false", "toggle wether to terminate after this action or not"},
599599
{"brief", "false", "1|0|true|false", "toggle brief or detailed documentation"},
600+
{"search", "", "mesh", "case-insensitive keyword: list every action whose name or documentation contains it (e.g. search=mesh). Useful for discovering the right action without scrolling the full help."},
600601
{"format", "text", "text|md", "output format. 'text' (default) is the usual human-readable help; 'md' emits a single Markdown table of action names + descriptions, used to regenerate the action list in README.md so it can't drift from the registered actions."}},
601602
[](){}, [&](){this->help();}, 0); // anonymous options are appended to "actions"
602603

@@ -1266,6 +1267,28 @@ void Tool::help()
12661267
const bool stop = mParser.get<bool>("exit");
12671268
const bool brief = mParser.get<bool>("brief");
12681269
const std::string format = mParser.get<std::string>("format");
1270+
const std::string search = mParser.get<std::string>("search");
1271+
1272+
if (!search.empty()) {
1273+
// Discovery aid: list every action whose primary/alias name OR its
1274+
// documentation contains the (case-insensitive) keyword. Detailed usage
1275+
// is printed for each hit so the user sees the options too.
1276+
const std::string key = toLowerCase(search);
1277+
VecS hits;
1278+
for (const auto &a : mParser.available) {
1279+
bool match = contains(toLowerCase(a.documentation), key);
1280+
for (const auto &n : a.names) match = match || contains(toLowerCase(n), key);
1281+
if (match) hits.push_back(a.names[0]);
1282+
}
1283+
if (hits.empty()) {
1284+
std::clog << "help: no action matches keyword \"" << search << "\"\n";
1285+
} else {
1286+
std::clog << "Actions matching \"" << search << "\":\n";
1287+
mParser.usage(hits, brief);
1288+
}
1289+
if (stop) std::exit(EXIT_SUCCESS);
1290+
return;
1291+
}
12691292

12701293
if (format == "md") {
12711294
// Emit a single Markdown table of registered actions for the README's

pendingchanges/openvdb_cmd.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ vdb_tool:
2323
- Action "-read" now supports ASCII XYZ point files (.xyz), where each line holds the x, y and z coordinates of a single point separated by whitespace. Blank lines and lines beginning with '#' are skipped as comments; any other line that does not parse as three numbers raises an error identifying the offending text. The points are accumulated as a vertex-only primitive (no faces), suitable for conversion to a VDB via -points2ls or -points2vdb. The data can also be streamed from standard input using the name "stdin.xyz".
2424
- Action "-mesh2ls/mesh2sdf" now supports generation of asymmetric narrow bands.
2525
- Improved error reporting when using unsupported actions and options.
26-
- Actions can now have multiple names, e.g. "-read", "-import", "-load", "-i".
26+
- Actions can now have multiple names (or aliases), e.g. "-read", "-import", "-load", "-i".
2727
- Added cutoff option to "-ls2fog" action.
2828
- Improved error reporting in vdb_tool (prints diagnostic error messages).
2929
- Improved error handling in vdb_tool (will recover from non-fatal errors).

0 commit comments

Comments
 (0)