Example #1
0
bool Config::parseCommandLine(const std::vector<CL_String8>& args) {
    namespace po = boost::program_options;

    po::options_description consoleDesc;
    consoleDesc.add_options()
    ("help,h", "Receive this message")
    ("patcherupdate", "Indicates that the patcher itself has just received an update")
    ("defaultconfig", "Write defaultConfig.xml file")
    ("shard", po::value<std::string>(), "The shard you want to connect to. If empty, shard selection dialog is shown. Shard name can also be given without --shard prefix")
    ;

    // transform vector to default argc, argv
    int argc = args.size();
#ifdef WIN32
    char** argv = new char*[argc];
#else
    char* argv[argc];
#endif
    for (int i = 0; i < argc; ++i) {
        argv[i] = const_cast<char*>(args[i].c_str());
    }

    po::variables_map consoleOptions;

    try {
        // parse console
        po::positional_options_description p;
        p.add("shard", 1);
        po::store(po::command_line_parser(argc, argv).options(consoleDesc).positional(p).run(), consoleOptions);

        if (consoleOptions.count("help")) {
            std::cout << consoleDesc << std::endl;
            return false;
        }

        if (consoleOptions.count("defaultconfig")) {
            // write default config
            boost::filesystem::path defaultPath("defaultConfig.xml");
            save(defaultPath, true);
        }

        po::notify(consoleOptions);

        if (consoleOptions.count("shard") > 0) {
            UnicodeString shard = StringConverter::fromUtf8(consoleOptions["shard"].as<std::string>());
            setShardName(shard);
        }
    } catch (const std::exception& ex) {
        LOG_EMERGENCY << "Error parsing command line: " << ex.what() << std::endl;
        return false;
    }

#ifdef WIN32
    free(argv);
#endif

    return true;
}
Example #2
0
    void ShardingState::gotShardName( const string& name ) {
        if ( setShardName( name ) )
            return;

        string clientAddr = cc().clientAddress(true);
        stringstream ss;

        // Same error as above, to match for reporting
        ss << "remote client " << clientAddr << " tried to initialize this host as shard " << name
           << ", but shard name was previously initialized as " << _shardName;
        msgasserted( 13298 , ss.str() );
    }