예제 #1
0
파일: skeleton.hpp 프로젝트: 1901/libmoost
 void add_options(boost::program_options::options_description& od, option_validator& opt_validator)
 {
    standard_options(od, opt_validator)
       ("log-level,l", boost::program_options::value<std::string>(&m_log_level)->default_value("info"), "default shell log level")
       ("logging-config", boost::program_options::value<std::string>(&m_log_config), "logging configuration file", validator::file(m_log_config))
       ;
 }
예제 #2
0
파일: transport-helper.c 프로젝트: samv/git
static int fetch_with_fetch(struct transport *transport,
			    int nr_heads, const struct ref **to_fetch)
{
	struct helper_data *data = transport->data;
	int i;
	struct strbuf buf = STRBUF_INIT;

	standard_options(transport);

	for (i = 0; i < nr_heads; i++) {
		const struct ref *posn = to_fetch[i];
		if (posn->status & REF_STATUS_UPTODATE)
			continue;

		strbuf_addf(&buf, "fetch %s %s\n",
			    sha1_to_hex(posn->old_sha1), posn->name);
	}

	strbuf_addch(&buf, '\n');
	if (write_in_full(data->helper->in, buf.buf, buf.len) != buf.len)
		die_errno("cannot send fetch to %s", data->name);

	while (1) {
		strbuf_reset(&buf);
		if (strbuf_getline(&buf, data->out, '\n') == EOF)
			exit(128); /* child died, message supplied already */

		if (!prefixcmp(buf.buf, "lock ")) {
			const char *name = buf.buf + 5;
			if (transport->pack_lockfile)
				warning("%s also locked %s", data->name, name);
			else
				transport->pack_lockfile = xstrdup(name);
		}
		else if (!buf.len)
			break;
		else
			warning("%s unexpectedly said: '%s'", data->name, buf.buf);
	}
	strbuf_release(&buf);
	return 0;
}
예제 #3
0
파일: skeleton.hpp 프로젝트: 1901/libmoost
   /**
    * \brief Set up and process command line options.
    */
   void process_cmdline_options(boost::program_options::options_description& cmdline_options, option_validator& opt_validator, int argc, char **argv)
   {
      add_options(cmdline_options);
      add_options(cmdline_options, opt_validator);

      standard_options(cmdline_options, opt_validator)
         .port("shell-port", "remote shell port when daemonised", m_shell_port)
         ("pidfile", boost::program_options::value<std::string>(&m_pidfile), "pidfile location")
         ("noerr,n", "shut up stderr (for thrift)")
         ("help,h", "output help message and exit")
         ("version", "output service version and exit")
         ("daemon", "daemonise (fork to background)")
         ;

      m_ownership.add_options(cmdline_options, opt_validator);
      m_logging.add_options(cmdline_options, opt_validator);

      boost::program_options::store(boost::program_options::parse_command_line(argc, argv, cmdline_options), m_opt_varmap);
      boost::program_options::notify(m_opt_varmap);
      m_options_valid = true;
   }
예제 #4
0
static int fetch_with_fetch(struct transport *transport,
			    int nr_heads, struct ref **to_fetch)
{
	struct helper_data *data = transport->data;
	int i;
	struct strbuf buf = STRBUF_INIT;

	standard_options(transport);

	for (i = 0; i < nr_heads; i++) {
		const struct ref *posn = to_fetch[i];
		if (posn->status & REF_STATUS_UPTODATE)
			continue;

		strbuf_addf(&buf, "fetch %s %s\n",
			    sha1_to_hex(posn->old_sha1), posn->name);
	}

	strbuf_addch(&buf, '\n');
	sendline(data, &buf);

	while (1) {
		recvline(data, &buf);

		if (!prefixcmp(buf.buf, "lock ")) {
			const char *name = buf.buf + 5;
			if (transport->pack_lockfile)
				warning("%s also locked %s", data->name, name);
			else
				transport->pack_lockfile = xstrdup(name);
		}
		else if (!buf.len)
			break;
		else
			warning("%s unexpectedly said: '%s'", data->name, buf.buf);
	}
	strbuf_release(&buf);
	return 0;
}
예제 #5
0
파일: pmgetopt.c 프로젝트: Aconex/pcp
static int
options(pmOptions *opts, char *buffer, size_t length)
{
    char *start, *finish, *token;
    pmLongOptions option = { 0 };

    /*
     * Two cases to deal with here - a "standard" option e.g. --host
     * which is presented as a single word (no description) OR a full
     * description of a command line option, in one of these forms:
     *
     *     --label              dump the archive label
     *     --background=COLOR   render background with given color
     *     -d, --desc           get and print metric description
     *     -b=N, --batch=N	fetch N metrics at a time
     *     -L                   use a local context connection
     *     -X=N                 offset resulting values by N units
     */
    if (pmDebug & DBG_TRACE_DESPERATE)
	fprintf(stderr, "%s: parsing option: '%s'", pmProgname, buffer);

    start = skip_whitespace(skip_nonwhitespace(buffer));
    finish = skip_nonwhitespace(start);
    if (start[0] != '-') {
	*finish = '\0';
	return append_text(opts, buffer, length);
    }

    token = skip_whitespace(finish);
    *finish = '\0';

    /* if a single word, this is the standard PCP option case - find it */
    if (!token || *token == '\0')
	return standard_options(opts, start);

    /* handle the first two example cases above -- long option only */
    if (start[1] == '-') {
	token = seek_character(start, '=');
	if (*token == '=') {
	    *token = '\0';	/* e.g. --background=COLOR  render ... */
	    token++;
	    finish = skip_nonwhitespace(token);
	    *finish = '\0';
	    if ((option.argname = strdup(token)) == NULL)
		__pmNoMem("argname", strlen(token), PM_FATAL_ERR);
	    option.has_arg = 1;
	} /* else e.g. --label  dump the archive label */
	if ((option.long_opt = strdup(start + 2)) == NULL)
	    __pmNoMem("longopt", strlen(start), PM_FATAL_ERR);
	token = skip_whitespace(finish + 1);
	if ((option.message = strdup(token)) == NULL)
	    __pmNoMem("message", strlen(token), PM_FATAL_ERR);
	return append_option(opts, &option);
    }

    /* handle next two example cases above -- both long and short options */
    token = seek_character(start, ',');
    if (*token == ',') {
	/* e.g. -b=N, --batch=N   fetch N metrics at a time */
	option.short_opt = (int)start[1];

	/* move onto extracting --batch, [=N], and "fetch..." */
	token++;	/* move past the comma */
	if (*token == '\0' && token - buffer < length)	/* move past a null */
	    token++;
	token = skip_whitespace(token);
	if ((token = seek_character(token, '-')) == NULL ||
	    (token - buffer >= length) || (token[1] != '-')) {
	    fprintf(stderr, "%s: expected long option at \"%s\", line %d ignored\n",
		    pmProgname, token, lineno);
	    return -EINVAL;
	}
	start = token + 2;	/* skip double-dash */
	if ((token = seek_character(start, '=')) != NULL && *token == '=') {
	    *token++ = '\0';
	    option.has_arg = 1;	/* now extract the argument name */
	    finish = skip_nonwhitespace(token);
	    *finish = '\0';
	    if ((option.argname = strdup(token)) == NULL)
		__pmNoMem("argname", strlen(token), PM_FATAL_ERR);
	} else {
	    finish = skip_nonwhitespace(start);
	    *finish = '\0';
	}
	if ((option.long_opt = strdup(start)) == NULL)
	    __pmNoMem("longopt", strlen(start), PM_FATAL_ERR);
	start = skip_whitespace(finish + 1);
	if ((option.message = strdup(start)) == NULL)
	    __pmNoMem("message", strlen(start), PM_FATAL_ERR);
	return append_option(opts, &option);
    }

    /* handle final two example cases above -- short options only */
    if (isspace(start[1])) {
	fprintf(stderr, "%s: expected short option at \"%s\", line %d ignored\n",
		pmProgname, start, lineno);
	return -EINVAL;
    }
    option.long_opt = "";
    option.short_opt = start[1];
    if ((token = seek_character(start, '=')) != NULL && *token == '=') {
	*token++ = '\0';
	option.has_arg = 1;	/* now extract the argument name */
	finish = skip_nonwhitespace(token);
	*finish = '\0';
	if ((option.argname = strdup(token)) == NULL)
	    __pmNoMem("argname", strlen(token), PM_FATAL_ERR);
	/* e.g. -X=N  offset resulting values by N units */
	start = skip_whitespace(finish + 2);
    } else {
	/* e.g. -L    use a local context connection */
	start = skip_whitespace(start + 3);
    }
    if ((option.message = strdup(start)) == NULL)
	__pmNoMem("message", strlen(start), PM_FATAL_ERR);
    return append_option(opts, &option);
}
예제 #6
0
파일: transport-helper.c 프로젝트: samv/git
static int push_refs(struct transport *transport,
		struct ref *remote_refs, int flags)
{
	int force_all = flags & TRANSPORT_PUSH_FORCE;
	int mirror = flags & TRANSPORT_PUSH_MIRROR;
	struct helper_data *data = transport->data;
	struct strbuf buf = STRBUF_INIT;
	struct child_process *helper;
	struct ref *ref;

	if (!remote_refs)
		return 0;

	helper = get_helper(transport);
	if (!data->push)
		return 1;

	for (ref = remote_refs; ref; ref = ref->next) {
		if (ref->peer_ref)
			hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
		else if (!mirror)
			continue;

		ref->deletion = is_null_sha1(ref->new_sha1);
		if (!ref->deletion &&
			!hashcmp(ref->old_sha1, ref->new_sha1)) {
			ref->status = REF_STATUS_UPTODATE;
			continue;
		}

		if (force_all)
			ref->force = 1;

		strbuf_addstr(&buf, "push ");
		if (!ref->deletion) {
			if (ref->force)
				strbuf_addch(&buf, '+');
			if (ref->peer_ref)
				strbuf_addstr(&buf, ref->peer_ref->name);
			else
				strbuf_addstr(&buf, sha1_to_hex(ref->new_sha1));
		}
		strbuf_addch(&buf, ':');
		strbuf_addstr(&buf, ref->name);
		strbuf_addch(&buf, '\n');
	}
	if (buf.len == 0)
		return 0;

	transport->verbose = flags & TRANSPORT_PUSH_VERBOSE ? 1 : 0;
	standard_options(transport);

	if (flags & TRANSPORT_PUSH_DRY_RUN) {
		if (set_helper_option(transport, "dry-run", "true") != 0)
			die("helper %s does not support dry-run", data->name);
	}

	strbuf_addch(&buf, '\n');
	if (write_in_full(helper->in, buf.buf, buf.len) != buf.len)
		exit(128);

	ref = remote_refs;
	while (1) {
		char *refname, *msg;
		int status;

		strbuf_reset(&buf);
		if (strbuf_getline(&buf, data->out, '\n') == EOF)
			exit(128); /* child died, message supplied already */
		if (!buf.len)
			break;

		if (!prefixcmp(buf.buf, "ok ")) {
			status = REF_STATUS_OK;
			refname = buf.buf + 3;
		} else if (!prefixcmp(buf.buf, "error ")) {
			status = REF_STATUS_REMOTE_REJECT;
			refname = buf.buf + 6;
		} else
			die("expected ok/error, helper said '%s'\n", buf.buf);

		msg = strchr(refname, ' ');
		if (msg) {
			struct strbuf msg_buf = STRBUF_INIT;
			const char *end;

			*msg++ = '\0';
			if (!unquote_c_style(&msg_buf, msg, &end))
				msg = strbuf_detach(&msg_buf, NULL);
			else
				msg = xstrdup(msg);
			strbuf_release(&msg_buf);

			if (!strcmp(msg, "no match")) {
				status = REF_STATUS_NONE;
				free(msg);
				msg = NULL;
			}
			else if (!strcmp(msg, "up to date")) {
				status = REF_STATUS_UPTODATE;
				free(msg);
				msg = NULL;
			}
			else if (!strcmp(msg, "non-fast forward")) {
				status = REF_STATUS_REJECT_NONFASTFORWARD;
				free(msg);
				msg = NULL;
			}
		}

		if (ref)
			ref = find_ref_by_name(ref, refname);
		if (!ref)
			ref = find_ref_by_name(remote_refs, refname);
		if (!ref) {
			warning("helper reported unexpected status of %s", refname);
			continue;
		}

		ref->status = status;
		ref->remote_status = msg;
	}
	strbuf_release(&buf);
	return 0;
}