示例#1
0
TEST(OptionsTest, nan)
{
    ProgramArgs args;
    double value;

    args.add("value", "Not a number", value);

    Options ops;
    ops.add("value", std::numeric_limits<double>::quiet_NaN());

    StringList cmdline = ops.toCommandLine();
    EXPECT_NO_THROW(args.parse(cmdline));
}
示例#2
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);
}
示例#3
0
bool DimBuilder::parseArgs(int argc, char *argv[])
{
    ProgramArgs args;

    args.add("input,i", "Filename of JSON specification of "
        "dimensions", m_input).setPositional();
    args.add("output,o", "Filename of output of C++ header representation of "
        "provided JSON.", m_output).setPositional();
    try
    {
        args.parse(argc, argv);
    }
    catch (arg_error& err)
    {
        std::cerr << err.m_error << "\n";
        return false;
    }
    return true;
}
示例#4
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);
    }
}
示例#5
0
bool NitfWrap::parseArgs(std::vector<std::string>& argList)
{
    ProgramArgs args;

    args.add("input,i", "Input filename", m_inputFile).setPositional();
    args.add("output,o", "Output filename",
        m_outputFile).setOptionalPositional();
    args.add("unwrap,u", "Unwrap NITF file", m_unwrap);
    try
    {
        m_nitfWriter.addArgs(args);
    }
    catch (arg_error& e)
    {
        throw error(e.m_error);
    }

    try
    {
        args.parse(argList);
    }
    catch (arg_error& e)
    {
        std::cerr << "nitfwrap: " << e.m_error << std::endl;
        outputHelp(args);
        return false;
    }

    if (!FileUtils::fileExists(m_inputFile))
    {
        std::ostringstream oss;

        oss << "Input file '" << m_inputFile << "' doesn't exist.";
        throw error(oss.str());
    }
    if (m_outputFile.empty())
        if (!m_unwrap)
            m_outputFile = FileUtils::stem(m_inputFile) + ".ntf";
    return true;
}