示例#1
0
TEST(OptionsTest, programargs)
{
    ProgramArgs args;

    bool falseDef, trueDef;

    args.add("falsedef", "False default", falseDef);
    args.add("truedef", "True default", trueDef, true);

    Options ops;
    ops.add("falsedef", false);
    ops.add("truedef", false);

    StringList cmdLine = ops.toCommandLine();
    args.parse(cmdLine);

    EXPECT_EQ(falseDef, false);
    EXPECT_EQ(trueDef, false);

    Options ops2;
    ops2.add("falsedef", true);
    ops2.add("truedef", true);

    cmdLine = ops2.toCommandLine();
    args.reset();
    args.parse(cmdLine);

    EXPECT_EQ(falseDef, true);
    EXPECT_EQ(trueDef, true);

    cmdLine.clear();
    args.reset();
    args.parse(cmdLine);

    EXPECT_EQ(falseDef, false);
    EXPECT_EQ(trueDef, true);
}
示例#2
0
文件: Kernel.cpp 项目: OldMogy/PDAL
void Kernel::doSwitches(int argc, const char *argv[], ProgramArgs& args)
{
    StringList stringArgs;
    OptionsMap& stageOptions = m_manager.stageOptions();

    // Scan the argument vector for extra stage options.  Pull them out and
    // stick them in the list.  Let the ProgramArgs handle everything else.
    // NOTE: This depends on the format being "option=value" rather than
    //   "option value".  This is what we've always expected, so no problem,
    //   but it would be better to be more flexible.
    for (int i = 0; i < argc; ++i)
    {
        std::string stageName, opName, value;

        if (parseOption(argv[i], stageName, opName, value))
        {
            Option op(opName, value);
            stageOptions[stageName].add(op);
        }
        else
            stringArgs.push_back(argv[i]);
    }

    try
    {
        addBasicSwitches(args);

        // parseSimple allows us to scan for the help option without
        // raising exception about missing arguments and so on.
        args.parseSimple(stringArgs);
        addSwitches(args);
        if (!m_showHelp)
        {
            args.reset();
            args.parse(stringArgs);
        }
    }
    catch (arg_error& e)
    {
        throw pdal_error(e.m_error);
    }
}