コード例 #1
0
ファイル: lsfs_options.cpp プロジェクト: 2510/xtreemfs
void LsfsOptions::ParseCommandLine(int argc, char** argv) {
  // Parse general options and retrieve unregistered options for own parsing.
  vector<string> options = Options::ParseCommandLine(argc, argv);

  // Read Volume URL from command line.
  po::positional_options_description p;
  p.add("mrc_volume_url", 1);
  po::options_description positional_options("List Volumes URL");
  positional_options.add_options()
    ("mrc_volume_url", po::value(&xtreemfs_url), "URL to MRC");

  // Parse command line.
  po::options_description all_descriptions;
  all_descriptions.add(positional_options).add(lsfs_descriptions_);
  po::variables_map vm;
  try {
    po::store(po::command_line_parser(options)
        .options(all_descriptions)
        .positional(p)
        .style(style::default_style & ~style::allow_guessing)
        .run(), vm);
    po::notify(vm);
  } catch(const std::exception& e) {
    // Rethrow boost errors due to invalid command line parameters.
    throw InvalidCommandLineParametersException(string(e.what()));
  }

  // Do not check parameters if the help shall be shown.
  if (show_help || empty_arguments_list || show_version) {
    return;
  }

  // Extract information from command line.
  Options::ParseURL(kMRC);

  // Check for MRC host
  if(service_addresses.empty()) {
    throw InvalidCommandLineParametersException("missing MRC host.");
  } else if (service_addresses.IsAddressList()) {
    throw InvalidCommandLineParametersException(
        "more than one MRC host was specified.");
  } else {
    mrc_service_address = service_addresses.GetAddresses().front();
  }
}
コード例 #2
0
void generic_options::parse(int argc, char* argv[])
{
    _progname = boost::filesystem::path(argv[0]).filename().string();

    boost::program_options::command_line_parser parser(argc, argv);
    boost::program_options::store(
            parser
                .options(all_options())
                .positional(positional_options())
                .run(),
            _vm);
    boost::program_options::notify(_vm);

    if(_vm.count("help"))
    {
        usage();
        std::exit(1);
    }
}
コード例 #3
0
ファイル: commandline.cpp プロジェクト: KingDuckZ/dindexer
	bool parse_commandline (int parArgc, char* parArgv[], po::variables_map& parVarMap) {
		po::options_description set_options(ACTION_NAME " options");
		set_options.add_options()
			("delete,d", "Delete tags instead of adding")
			("alltags,a", "Only allowed when --delete is also specified - ignores any given tag list and delete all tags associated to the matching elements instead")
			//("option,o", po::value<std::string>()->default_value("default_value"), "Help message")
			("ids", po::value<std::string>(), "Comma-separated list of IDs of files to be tagged")
			("set,s", po::value<uint32_t>(), "Limit matching to files belonging to the specified set ID")
		;

		po::options_description positional_options("Positional options");
		positional_options.add_options()
			("tags", po::value<std::string>(), "comma-separated tag list")
			("globs", po::value<std::vector<std::string>>(), "List of globs to match against")
		;

		const auto desc = dinlib::get_default_commandline();
		po::options_description all("Available options");
		po::positional_options_description pd;
		all.add(desc).add(positional_options).add(set_options);
		pd.add("tags", 1).add("globs", -1);
		try {
			po::store(po::command_line_parser(parArgc, parArgv).options(all).positional(pd).run(), parVarMap);
		}
		catch (const po::validation_error& err) {
			throw dinlib::ValidationError(err);
		}

		po::notify(parVarMap);

		const char* const help_text = "[options...] tag[,tag2...] (--ids id1[,id2...] | <glob> [glob...])";
		if (dinlib::manage_common_commandline(std::cout, ACTION_NAME, help_text, parVarMap, {std::cref(desc), std::cref(set_options)})) {
			return true;
		}

		return false;
	}
コード例 #4
0
ファイル: mkfs_options.cpp プロジェクト: amokoma/xtreemfs
void MkfsOptions::ParseCommandLine(int argc, char** argv) {
  // Parse general options and retrieve unregistered options for own parsing.
  vector<string> options = Options::ParseCommandLine(argc, argv);

  // Read Volume URL from command line.
  po::positional_options_description p;
  p.add("mrc_volume_url", 1);
  po::options_description positional_options("Create Volume URL");
  positional_options.add_options()
    ("mrc_volume_url", po::value(&xtreemfs_url), "volume to create");

  // Parse command line.
  po::options_description all_descriptions;
  all_descriptions.add(positional_options).add(mkfs_descriptions_);
  po::variables_map vm;
  try {
    po::store(po::command_line_parser(options)
        .options(all_descriptions)
        .positional(p)
        .style(style::default_style & ~style::allow_guessing)
        .run(), vm);
    po::notify(vm);
  } catch(const std::exception& e) {
    // Rethrow boost errors due to invalid command line parameters.
    throw InvalidCommandLineParametersException(string(e.what()));
  }

  // Do not check parameters if the help shall be shown.
  if (show_help || empty_arguments_list || show_version) {
    return;
  }

  // Extract information from command line.
  Options::ParseURL(kMRC);

  // Check for MRC host
  if(service_addresses.empty()) {
    throw InvalidCommandLineParametersException("missing MRC host.");
  } else if (service_addresses.IsAddressList()) {
    throw InvalidCommandLineParametersException(
        "more than one MRC host was specified.");
  } else {
    mrc_service_address = service_addresses.GetAddresses().front();
  }

  // Check for required parameters.
  if (volume_name.empty()) {
    throw InvalidCommandLineParametersException("missing volume name.");
  }

  // Abort the user explicitly specified numeric ids as owner.
  if (CheckIfUnsignedInteger(owner_username)) {
    throw InvalidCommandLineParametersException("Do not use numeric IDs as "
        "owner. Use names instead, e.g. \"root\" instead of \"0\".");
  }
  if (CheckIfUnsignedInteger(owner_groupname)) {
    throw InvalidCommandLineParametersException("Do not use numeric IDs as "
        "owner group. Use names instead, e.g. \"root\" instead of \"0\".");
  }

  // Convert the mode from octal to decimal.
  volume_mode_decimal = OctalToDecimal(volume_mode_octal);

  if (boost::iequals(access_policy_type_string, "NULL")) {
    access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_NULL;
  } else if (boost::iequals(access_policy_type_string, "POSIX")) {
    access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_POSIX;
  } else if (boost::iequals(access_policy_type_string, "VOLUME")) {
    access_policy_type = xtreemfs::pbrpc::ACCESS_CONTROL_POLICY_VOLUME;
  } else {
    throw InvalidCommandLineParametersException("Unknown access policy (" +
        access_policy_type_string + ") specified.");
  }

  if (boost::iequals(default_striping_policy_type_string, "RAID0")) {
    default_striping_policy_type = xtreemfs::pbrpc::STRIPING_POLICY_RAID0;
  } else {
    throw InvalidCommandLineParametersException("Currently the RAID0 striping"
        "policy is the only one available. Set the stripe width (see -w) to 1"
        " to disable striping at all.");
  }

  // Process volume attributes shortcuts.
  if (chown_non_root) {
    volume_attributes_strings.push_back("chown_non_root=true");
  }
  if (grid_auth_mode_globus) {
    volume_attributes_strings.push_back("globus_gridmap=true");
  }
  if (grid_auth_mode_unicore) {
    volume_attributes_strings.push_back("unicore_uudb=true");
  }

  // Parse list of volume attributes.
  for (size_t i = 0; i < volume_attributes_strings.size(); i++) {
    // Check if there is exactly one "=" delimiter.
    size_t first_match = volume_attributes_strings[i].find_first_of("=");
    if (first_match == string::npos) {
      throw InvalidCommandLineParametersException("The attribute key/value pair"
          " " + volume_attributes_strings[i] + " misses a \"=\".");
    }
    size_t next_match = volume_attributes_strings[i].find_first_of(
        "=",
        first_match + 1);
    if (next_match != string::npos) {
      throw InvalidCommandLineParametersException("The attribute key/value pair"
          " " + volume_attributes_strings[i] + " must not contain"
          " multiple \"=\".");
    }

    // Parse attribute.
    KeyValuePair* attribute = new KeyValuePair();
    attribute->set_key(volume_attributes_strings[i].substr(0, first_match));
    attribute->set_value(volume_attributes_strings[i].substr(
        min(first_match + 1, volume_attributes_strings[i].length()),
        max(static_cast<size_t>(0),
            volume_attributes_strings[i].length() - first_match)));
    volume_attributes.push_back(attribute);
  }
}