Skip to content

Commit

Permalink
Provision redirection aliases
Browse files Browse the repository at this point in the history
Signed-off-by: methylDragon <methylDragon@gmail.com>
  • Loading branch information
methylDragon committed Apr 27, 2022
1 parent 26f1a89 commit e3de70a
Show file tree
Hide file tree
Showing 44 changed files with 364 additions and 9,746 deletions.
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/App.hpp>
#include <external-cli/gz/utils/cli/App.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/CLI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/CLI.hpp>
#include <external-cli/gz/utils/cli/CLI.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Config.hpp>
#include <external-cli/gz/utils/cli/Config.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/ConfigFwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/ConfigFwd.hpp>
#include <external-cli/gz/utils/cli/ConfigFwd.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Error.hpp>
#include <external-cli/gz/utils/cli/Error.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Formatter.hpp>
#include <external-cli/gz/utils/cli/Formatter.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/FormatterFwd.hpp>
#include <external-cli/gz/utils/cli/FormatterFwd.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Macros.hpp>
#include <external-cli/gz/utils/cli/Macros.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Option.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Option.hpp>
#include <external-cli/gz/utils/cli/Option.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Split.hpp>
#include <external-cli/gz/utils/cli/Split.hpp>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/StringTools.hpp>
#include <external-cli/gz/utils/cli/StringTools.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Timer.hpp>
#include <external-cli/gz/utils/cli/Timer.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/TypeTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/TypeTools.hpp>
#include <external-cli/gz/utils/cli/TypeTools.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Validators.hpp>
#include <external-cli/gz/utils/cli/Validators.hpp>
2 changes: 1 addition & 1 deletion cli/include/external-cli/ignition/utils/cli/Version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*
*/

#include <CLI/Version.hpp>
#include <external-cli/gz/utils/cli/Version.hpp>
154 changes: 1 addition & 153 deletions cli/include/ignition/utils/cli/IgnitionFormatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,156 +15,4 @@
*
*/

#ifndef IGNITION_UTILS_CLI_IGNITION_FORMATTER_HPP_
#define IGNITION_UTILS_CLI_IGNITION_FORMATTER_HPP_

#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <unordered_map>

#include "ignition/utils/cli/App.hpp"
#include "ignition/utils/cli/FormatterFwd.hpp"

//////////////////////////////////////////////////
/// \brief CLI Formatter class that implements custom Ignition-specific
/// formatting.
///
/// More information on custom formatters:
/// https://cliutils.github.io/CLI11/book/chapters/formatting.html
class IgnitionFormatter: public CLI::Formatter {

//////////////////////////////////////////////////
public: explicit IgnitionFormatter(const CLI::App *_app)
{
// find needs/needed_by for root options
for (const CLI::Option *appOpt: _app->get_options())
{
for(const CLI::Option *needsOpt : appOpt->get_needs())
{
this->needed_by.insert({needsOpt->get_name(), appOpt->get_name()});
this->needs.insert({appOpt->get_name(), needsOpt->get_name()});
}
}

// find needs/needed_by for subcommand (or command group) options
auto subcommands = _app->get_subcommands([](const CLI::App*){return true;});
for (const CLI::App *sub : subcommands)
{
// find needs/needed_by for root options
for (const CLI::Option *subOpt: sub->get_options())
{
for(const CLI::Option *needsOpt : subOpt->get_needs())
{
this->needed_by.insert({needsOpt->get_name(), subOpt->get_name()});
this->needs.insert({subOpt->get_name(), needsOpt->get_name()});
}
}
}
}

//////////////////////////////////////////////////
public: std::string make_option_name(
const CLI::Option *opt, bool is_positional) const override {
if (is_positional)
return opt->get_name(true, false);

std::stringstream out;

auto snames = opt->get_snames();
auto lnames = opt->get_lnames();

std::vector<std::string> sname_list;
std::transform(snames.begin(), snames.end(), std::back_inserter(sname_list),
[](const std::string &sname) { return "-" + sname; });

std::vector<std::string> lname_list;
std::transform(lnames.begin(), lnames.end(), std::back_inserter(lname_list),
[](const std::string &lname) { return "--" + lname; });

// If no short options, just use long
if (sname_list.empty())
{
out << CLI::detail::join(lname_list);
}
else
{
out << CLI::detail::join(sname_list);
// Put lnames in brackets to look like ruby formatting
if (!lnames.empty())
{
out << " [" << CLI::detail::join(lname_list) << "]";
}
}

return out.str();
}


//////////////////////////////////////////////////
public: std::string make_option_opts(const CLI::Option *opt) const override {
std::stringstream out;

if(opt->get_type_size() != 0) {
if(!opt->get_type_name().empty())
out << " " << get_label(opt->get_type_name());
if(!opt->get_default_str().empty())
out << "=" << opt->get_default_str();
if(opt->get_expected_max() == CLI::detail::expected_max_vector_size)
out << " ...";
else if(opt->get_expected_min() > 1)
out << " x " << opt->get_expected();
}
if(!opt->get_envname().empty())
out << " (" << get_label("Env") << ":" << opt->get_envname() << ")";
return out.str();
}


//////////////////////////////////////////////////
std::string make_option_desc(const CLI::Option *opt) const override {
std::stringstream out;

out << opt->get_description();

if (opt->get_required())
{
out << "\nREQUIRED";
}

auto range = this->needs.equal_range(opt->get_name());
std::for_each(
range.first,
range.second,
[&out](const auto &opt_name)
{
out << "\nRequires: " << opt_name.second;
});

range = this->needed_by.equal_range(opt->get_name());
std::for_each(
range.first,
range.second,
[&out](const auto &opt_name)
{
out << "\nRequired by: " << opt_name.second;
});

if (!opt->get_excludes().empty()) {
out << "\n" << get_label("Excludes") << ":";
for(const CLI::Option *op : opt->get_excludes())
out << " " << op->get_name();
}

return out.str() + '\n';
}

/// \brief Track dependent options
private: std::unordered_multimap<std::string, std::string> needs;

/// \brief Track dependent options (inverse)
private: std::unordered_multimap<std::string, std::string> needed_by;
};

#endif // IGNITION_UTILS_CLI_IGNITION_FORMATTER_HPP_
#include <gz/utils/cli/GzFormatter.hpp>
Loading

0 comments on commit e3de70a

Please sign in to comment.