示例#1
0
/*
 * Print usage for a subcommand and object.
 *
 * input:
 *  usage type - GENERAL_USAGE, HELP_USAGE, DETAIL_USAGE
 *  subcommand - pointer to subcommand_t structure
 *  objp - pointer to a object_t structure
 *
 * Returns:
 *  none
 *
 */
static void
subUsageObject(uint_t usageType, subcommand_t *subcommand, object_t *objp)
{
	int i;
	objectRules_t *objRules = NULL;
	opCmd_t *opCmd = NULL;
	optionProp_t *options;
	char *optionArgDesc;
	char *longOpt;


	if (getObjectRules(objp->value, &objRules) != 0) {
		/*
		 * internal subcommand rules table error
		 * no object entry in object
		 */
		assert(0);
	}

	opCmd = &(objRules->opCmd);

	if (opCmd->invOpCmd & subcommand->value) {
		return;
	}

	options = getOptions(objp->value, subcommand->value);

	/* print generic subcommand usage */
	(void) fprintf(stdout, "\t%s %s ", commandName, subcommand->name);

	/* print object */
	(void) fprintf(stdout, "%s ", objp->name);

	/* print options if applicable */
	if (options != NULL) {
		if (options->required) {
			(void) fprintf(stdout, "%s", gettext("<"));
		} else {
			(void) fprintf(stdout, "%s", gettext("["));
		}
		(void) fprintf(stdout, "%s", gettext("OPTIONS"));
		if (options->required) {
			(void) fprintf(stdout, "%s ", gettext(">"));
		} else {
			(void) fprintf(stdout, "%s ", gettext("]"));
		}
	}

	/* print operand requirements */
	if (opCmd->optOpCmd & subcommand->value) {
		(void) fprintf(stdout, gettext("["));
	}
	if (!(opCmd->noOpCmd & subcommand->value)) {
		(void) fprintf(stdout, gettext("<"));
		if (objRules->operandDefinition) {
			(void) fprintf(stdout, "%s",
			    objRules->operandDefinition);
		} else {
			/*
			 * Missing operand description
			 * from table
			 */
			assert(0);
		}
	}
	if (opCmd->multOpCmd & subcommand->value) {
		(void) fprintf(stdout, gettext(" ..."));
	}
	if (!(opCmd->noOpCmd & subcommand->value)) {
		(void) fprintf(stdout, gettext(">"));
	}
	if (opCmd->optOpCmd & subcommand->value) {
		(void) fprintf(stdout, gettext("]"));
	}

	if (usageType == HELP_USAGE) {
		(void) fprintf(stdout, "\n");
		return;
	}

	/* print options for subcommand, object */
	if (options != NULL && options->optionString != NULL) {
		(void) fprintf(stdout, "\n\t%s:", gettext("OPTIONS"));
		for (i = 0; i < strlen(options->optionString); i++) {
			if ((longOpt = getLongOption(
					    options->optionString[i]))
			    == NULL) {
			    /* no long option exists for short option */
			    assert(0);
			}
			(void) fprintf(stdout, "\n\t\t-%c, --%s  ",
			    options->optionString[i], longOpt);
			optionArgDesc =
			    getOptionArgDesc(options->optionString[i]);
			if (optionArgDesc != NULL) {
				(void) fprintf(stdout, "<%s>", optionArgDesc);
			}
			if (options->exclusive &&
			    strchr(options->exclusive,
				    options->optionString[i])) {
				(void) fprintf(stdout, " (%s)",
				gettext("exclusive"));
			}
		}
	}
	(void) fprintf(stdout, "\n");
}
示例#2
0
/*
 * Print usage for a subcommand.
 *
 * input:
 *  usage type - GENERAL_USAGE, DETAIL_USAGE
 *  subcommand - pointer to subCommandProps_t structure
 *
 * Returns:
 *  none
 *
 */
static void
subUsage(uint_t usageType, subCommandProps_t *subcommand)
{
	int i;
	char *optionArgDesc;
	char *longOpt;

	if (usageType == GENERAL_USAGE) {
		printf("%s:\t%s %s [", gettext("Usage"), commandName,
		    subcommand->name);
		for (i = 0; standardSubCmdOptions[i].name; i++) {
			printf("-%c", standardSubCmdOptions[i].val);
			if (standardSubCmdOptions[i+1].name)
				printf(",");
		}
		fprintf(stdout, "]\n");
		return;
	}

	/* print subcommand usage */
	printf("\n%s:\t%s %s ", gettext("Usage"), commandName,
	    subcommand->name);

	/* print options if applicable */
	if (subcommand->optionString != NULL) {
		if (subcommand->required) {
			printf("%s", gettext("<"));
		} else {
			printf("%s", gettext("["));
		}
		printf("%s", gettext("OPTIONS"));
		if (subcommand->required) {
			printf("%s ", gettext(">"));
		} else {
			printf("%s ", gettext("]"));
		}
	}

	/* print operand requirements */
	if (!(subcommand->operand & OPERAND_NONE) &&
	    !(subcommand->operand & OPERAND_MANDATORY)) {
		printf(gettext("["));
	}

	if (subcommand->operand & OPERAND_MANDATORY) {
		printf(gettext("<"));
	}

	if (!(subcommand->operand & OPERAND_NONE)) {
		assert(subcommand->operandDefinition);
		printf("%s", subcommand->operandDefinition);
	}

	if (subcommand->operand & OPERAND_MULTIPLE) {
		printf(gettext(" ..."));
	}

	if (subcommand->operand & OPERAND_MANDATORY) {
		printf(gettext(">"));
	}

	if (!(subcommand->operand & OPERAND_NONE) &&
	    !(subcommand->operand & OPERAND_MANDATORY)) {
		printf(gettext("]"));
	}

	/* print options for subcommand */
	if (subcommand->optionString != NULL) {
		printf("\n\t%s:", gettext("OPTIONS"));
		for (i = 0; i < strlen(subcommand->optionString); i++) {
			assert((longOpt = getLongOption(
			    subcommand->optionString[i])) != NULL);
			printf("\n\t\t-%c, --%s  ", subcommand->optionString[i],
			    longOpt);
			optionArgDesc =
			    getOptionArgDesc(subcommand->optionString[i]);
			if (optionArgDesc != NULL) {
				printf("<%s>", optionArgDesc);
			}
			if (subcommand->exclusive &&
			    strchr(subcommand->exclusive,
			    subcommand->optionString[i])) {
				printf(" (%s)", gettext("exclusive"));
			}
		}
	}
	fprintf(stdout, "\n");
}