Пример #1
0
std::vector<option> makeLongOptions(const std::vector<CmdlineOpt> &opts) {
    std::vector<option> options;
    for (const auto &opt : opts) {
        const auto &o = commandlineOptions.at(opt);
        options.push_back({ o.longOption, o.hasArg, nullptr, static_cast<int>(opt) });
    }

    options.push_back({ nullptr, 0, nullptr, 0 });
    return options;
}
Пример #2
0
std::string makeShortOptions(const std::vector<CmdlineOpt> &opts) {
    std::stringstream optstr;
    optstr << ":";

    for (const auto &opt : opts) {
        const auto &o = commandlineOptions.at(opt);
        optstr << o.shortOption;

        if (o.hasArg == OptHasArg::RequiredArgument)
            optstr << ":";
    }

    return optstr.str();
}
Пример #3
0
std::string makeHelp(void) {

    std::size_t optWidth = 33;

    auto head = [] (const std::string &header, CmdlineOpt opt) -> std::string {
        return header + " (with -" + commandlineOptions.at(opt).shortOption
                      + " or --" + commandlineOptions.at(opt).longOption + ")";
    };

    auto opt = [&optWidth] (CmdlineOpt opt) -> std::string {
        auto prefix = std::string("  -") + commandlineOptions.at(opt).shortOption
                    + ", --" + commandlineOptions.at(opt).helpArgument;
        auto spaceLen = optWidth > prefix.length() ? optWidth - prefix.length() : 1;
        return prefix + std::string(spaceLen, ' ')
                      + commandlineOptions.at(opt).helpDescription;
    };

    std::stringstream helpStr;

    helpStr << "Usage: cyad [OPTIONS]" << std::endl << std::endl;

    helpStr << head("Bucket set options", CmdlineOpt::SetBucket) << std::endl;
    helpStr << opt(CmdlineOpt::SetBucket) << std::endl;
    helpStr << opt(CmdlineOpt::Type) << std::endl;
    helpStr << opt(CmdlineOpt::Metadata) << std::endl;
    helpStr << std::endl;

    helpStr << head("Bucket delete options", CmdlineOpt::DeleteBucket) << std::endl;
    helpStr << opt(CmdlineOpt::DeleteBucket) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policy set options", CmdlineOpt::SetPolicy) << std::endl;
    helpStr << opt(CmdlineOpt::Bucket) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << opt(CmdlineOpt::Type) << std::endl;
    helpStr << opt(CmdlineOpt::Metadata) << std::endl;
    helpStr << opt(CmdlineOpt::Bulk) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policy erase options", CmdlineOpt::Erase) << std::endl;
    helpStr << opt(CmdlineOpt::Erase) << std::endl;
    helpStr << opt(CmdlineOpt::Recursive) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Administrative policy check options", CmdlineOpt::Check) << std::endl;
    helpStr << opt(CmdlineOpt::Bucket) << std::endl;
    helpStr << opt(CmdlineOpt::Recursive) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policies list options", CmdlineOpt::ListPolicies) << std::endl;
    helpStr << opt(CmdlineOpt::ListPolicies) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policies descriptions list options", CmdlineOpt::ListPoliciesDesc)
            << std::endl;
    helpStr << opt(CmdlineOpt::ListPoliciesDesc) << std::endl;
    helpStr << std::endl;

    helpStr << head("Help options", CmdlineOpt::Help) << std::endl;
    helpStr << opt(CmdlineOpt::Help);

    return helpStr.str();
}
Пример #4
0
std::string makeHelp(void) {

    std::size_t optWidth = 33;

    auto head = [] (const std::string &header, CmdlineOpt opt) -> std::string {
        return header + " (with -" + commandlineOptions.at(opt).shortOption
        + " or --" + commandlineOptions.at(opt).longOption + ")";
    };

    auto opt = [&optWidth] (CmdlineOpt opt) -> std::string {
        auto prefix = std::string("  -") + commandlineOptions.at(opt).shortOption
        + ", --" + commandlineOptions.at(opt).helpArgument;
        auto spaceLen = optWidth > prefix.length() ? optWidth - prefix.length() : 1;
        return prefix + std::string(spaceLen, ' ')
        + commandlineOptions.at(opt).helpDescription
        + (commandlineOptions.at(opt).isReq == Required ? " - required" : "");
    };

    std::stringstream helpStr;

    helpStr << "Usage: cyad [OPTIONS]" << std::endl << std::endl;

    helpStr << head("Bucket set options", CmdlineOpt::SetBucket) << std::endl;
    helpStr << opt(CmdlineOpt::SetBucket) << std::endl;
    helpStr << opt(CmdlineOpt::Type) << std::endl;
    helpStr << opt(CmdlineOpt::Metadata) << std::endl;
    helpStr << std::endl;

    helpStr << head("Bucket delete options", CmdlineOpt::DeleteBucket) << std::endl;
    helpStr << opt(CmdlineOpt::DeleteBucket) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policy set options", CmdlineOpt::SetPolicy) << std::endl;
    helpStr << opt(CmdlineOpt::Bucket) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << opt(CmdlineOpt::Type) << std::endl;
    helpStr << opt(CmdlineOpt::Metadata) << std::endl;
    helpStr << opt(CmdlineOpt::Bulk) << std::endl;
    helpStr << std::endl;

    helpStr << "Bulk file" << std::endl;
    helpStr << "  For each policy a single line should be present with the folowing information:";
    helpStr << std::endl;
    helpStr << "    <bucket>;<client>;<user>;<privilege>;<type as decimal>;[metadata]" << std::endl;
    helpStr << "  In stdin input mode, double empty line ends this mode." << std::endl;
    helpStr << std::endl;

    helpStr << head("Policy erase options", CmdlineOpt::Erase) << std::endl;
    helpStr << opt(CmdlineOpt::Erase) << std::endl;
    helpStr << opt(CmdlineOpt::Recursive) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Administrative policy check options", CmdlineOpt::Check) << std::endl;
    helpStr << opt(CmdlineOpt::Bucket) << std::endl;
    helpStr << opt(CmdlineOpt::Recursive) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policies list options", CmdlineOpt::ListPolicies) << std::endl;
    helpStr << opt(CmdlineOpt::ListPolicies) << std::endl;
    helpStr << opt(CmdlineOpt::Client) << std::endl;
    helpStr << opt(CmdlineOpt::User) << std::endl;
    helpStr << opt(CmdlineOpt::Privilege) << std::endl;
    helpStr << std::endl;

    helpStr << head("Policies descriptions list options", CmdlineOpt::ListPoliciesDesc)
            << std::endl;
    helpStr << opt(CmdlineOpt::ListPoliciesDesc) << std::endl;
    helpStr << std::endl;

    helpStr << head("Help options", CmdlineOpt::Help) << std::endl;
    helpStr << opt(CmdlineOpt::Help);

    return helpStr.str();
}