Skip to content

Commit

Permalink
Shorter cli commands (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Oct 19, 2021
1 parent 2db5f16 commit 24f6d18
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
11 changes: 5 additions & 6 deletions apps/yimage/yimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,11 @@ int main(int argc, const char* argv[]) {
auto params = app_params{};
auto cli = make_cli("yimage", "process and view images");
add_command_var(cli, params.command);
add_options(add_command(cli, "convert", "convert images"), params.convert);
add_options(add_command(cli, "view", "view images"), params.view);
add_options(add_command(cli, "grade", "grade images"), params.grade);
add_options(add_command(cli, "diff", "diff two images"), params.diff);
add_options(
add_command(cli, "setalpha", "set images alpha"), params.setalpha);
add_command(cli, "convert", params.convert, "convert images");
add_command(cli, "view", params.view, "view images");
add_command(cli, "grade", params.grade, "grade images");
add_command(cli, "diff", params.diff, "diff two images");
add_command(cli, "setalpha", params.setalpha, "set images alpha");
parse_cli(cli, argc, argv);

// dispatch commands
Expand Down
11 changes: 5 additions & 6 deletions apps/ymesh/ymesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,11 @@ int main(int argc, const char* argv[]) {
auto params = app_params{};
auto cli = make_cli("ymesh", "process and view meshes");
add_command_var(cli, params.command);
add_options(add_command(cli, "view", "view shapes"), params.view);
add_options(
add_command(cli, "glview", "view shapes with OpenGL"), params.glview);
add_options(add_command(cli, "glpath", "trace paths"), params.glpath);
add_options(add_command(cli, "glpathd", "debug paths"), params.glpathd);
add_options(add_command(cli, "glsculpt", "sculpt meshes"), params.glsculpt);
add_command(cli, "view", params.view, "view shapes");
add_command(cli, "glview", params.glview, "view shapes with OpenGL");
add_command(cli, "glpath", params.glpath, "trace paths");
add_command(cli, "glpathd", params.glpathd, "debug paths");
add_command(cli, "glsculpt", params.glsculpt, "sculpt meshes");
parse_cli(cli, argc, argv);

// dispatch commands
Expand Down
11 changes: 5 additions & 6 deletions apps/yscene/yscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,11 @@ int main(int argc, const char* argv[]) {
auto params = app_params{};
auto cli = make_cli("yscene", "process and view scenes");
add_command_var(cli, params.command);
add_options(add_command(cli, "convert", "convert scenes"), params.convert);
add_options(add_command(cli, "info", "print scenes info"), params.info);
add_options(add_command(cli, "render", "render scenes"), params.render);
add_options(add_command(cli, "view", "view scenes"), params.view);
add_options(
add_command(cli, "glview", "view scenes with OpenGL"), params.glview);
add_command(cli, "convert", params.convert, "convert scenes");
add_command(cli, "info", params.info, "print scenes info");
add_command(cli, "render", params.render, "render scenes");
add_command(cli, "view", params.view, "view scenes");
add_command(cli, "glview", params.glview, "view scenes with OpenGL");
parse_cli(cli, argc, argv);

// dispatch commands
Expand Down
20 changes: 9 additions & 11 deletions apps/yshape/yshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,15 @@ int main(int argc, const char** argv) {
auto params = app_params{};
auto cli = make_cli("yshape", "Process and view shapes");
add_command_var(cli, params.command);
add_options(add_command(cli, "convert", "convert shapes"), params.convert);
add_options(add_command(cli, "fvconvert", "convert face-varying shapes"),
params.fvconvert);
add_options(add_command(cli, "view", "view shapes"), params.view);
add_options(add_command(cli, "heightfield", "create an heightfield"),
params.heightfield);
add_options(add_command(cli, "hair", "grow hairs on a shape"), params.hair);
add_options(
add_command(cli, "sample", "sample points on a shape"), params.sample);
add_options(
add_command(cli, "glview", "view shapes with OpenGL"), params.glview);
add_command(cli, "convert", params.convert, "convert shapes");
add_command(
cli, "fvconvert", params.fvconvert, "convert face-varying shapes");
add_command(cli, "view", params.view, "view shapes");
add_command(
cli, "heightfield", params.heightfield, "create an heightfield");
add_command(cli, "hair", params.hair, "grow hairs on a shape");
add_command(cli, "sample", params.sample, "sample points on a shape");
add_command(cli, "glview", params.glview, "view shapes with OpenGL");
parse_cli(cli, argc, argv);

// dispatch commands
Expand Down
16 changes: 16 additions & 0 deletions libs/yocto/yocto_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ inline cli_command& add_command(
// add command variable
template <typename T>
inline void add_command_var(cli_command& cli, T& value);
// add command by invoking add_options for the struct type passed
template <typename T>
inline cli_command& add_command(
cli_command& cli, const string& name, T& value, const string& usage);

// add option
template <typename T>
Expand Down Expand Up @@ -174,6 +178,9 @@ namespace yocto {
// Cli map. Cannot use map or unordered_map
template <typename Key, typename Value>
struct cli_map {
// reserve to ensure pointer stability
cli_map() { _data.reserve(256); }

bool empty() const { return _data.empty(); }
bool contains(const Key& key) const {
for (auto& [key_, value] : _data)
Expand Down Expand Up @@ -383,6 +390,15 @@ inline void add_command_var(cli_command& cli, T& value) {
};
}

// add command by invoking add_options for the struct type passed
template <typename T>
inline cli_command& add_command(
cli_command& cli, const string& name, T& value, const string& usage) {
auto& cmd = add_command(cli, name, usage);
add_options(cmd, value);
return cmd;
}

// add option
template <typename T>
inline void add_option(
Expand Down

0 comments on commit 24f6d18

Please sign in to comment.