ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv)
{
	int rc = 0;
	uint8_t fru_id = 0;

	if (argc < 1) {
		rc = ipmi_fru_print_all(intf);
	}
	else if (strncmp(argv[0], "help", 4) == 0) {
		ipmi_fru_help();
		return 0;
	}
	else if (strncmp(argv[0], "print", 5) == 0 ||
		strncmp(argv[0], "list", 4) == 0) {
		if (argc > 1) {
			if (strcmp(argv[1], "help") == 0) {
				lprintf(LOG_NOTICE, "fru print [fru id] - print information about FRU(s)");
				return 0;
			}

			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			rc = __ipmi_fru_print(intf, fru_id);
		} else {
			rc = ipmi_fru_print_all(intf);
		}
	}
	else if (!strncmp(argv[0], "read", 5)) {
		if (argc > 1 && strcmp(argv[1], "help") == 0) {
			ipmi_fru_read_help();
			return 0;
		} else if (argc < 3) {
			lprintf(LOG_ERR, "Not enough parameters given.");
			ipmi_fru_read_help();
			return -1;
		}

		if (is_fru_id(argv[1], &fru_id) != 0)
			return -1;

		/* There is a file name in the parameters */
		if (is_valid_filename(argv[2]) != 0)
			return -1;

		if (verbose) {
			printf("FRU ID           : %d\n", fru_id);
			printf("FRU File         : %s\n", argv[2]);
		}
		/* TODO - rc is missing */
		ipmi_fru_read_to_bin(intf, argv[2], fru_id);
	}
	else if (!strncmp(argv[0], "write", 5)) {
		if (argc > 1 && strcmp(argv[1], "help") == 0) {
			ipmi_fru_write_help();
			return 0;
		} else if (argc < 3) {
			lprintf(LOG_ERR, "Not enough parameters given.");
			ipmi_fru_write_help();
			return -1;
		}

		if (is_fru_id(argv[1], &fru_id) != 0)
			return -1;

		/* There is a file name in the parameters */
		if (is_valid_filename(argv[2]) != 0)
			return -1;

		if (verbose) {
			printf("FRU ID           : %d\n", fru_id);
			printf("FRU File         : %s\n", argv[2]);
		}
		/* TODO - rc is missing */
		ipmi_fru_write_from_bin(intf, argv[2], fru_id);
	}
	else if (!strncmp(argv[0], "upgEkey", 7)) {
		if (argc > 1 && strcmp(argv[1], "help") == 0) {
			ipmi_fru_upgekey_help();
			return 0;
		} else if (argc < 3) {
			lprintf(LOG_ERR, "Not enough parameters given.");
			ipmi_fru_upgekey_help();
			return -1;
		}

		if (is_fru_id(argv[1], &fru_id) != 0)
			return -1;

		/* There is a file name in the parameters */
		if (is_valid_filename(argv[2]) != 0)
			return -1;

		rc = ipmi_fru_upg_ekeying(intf, argv[2], fru_id);
	}
	else if (!strncmp(argv[0], "internaluse", 11)) {
		if (argc > 1 && strcmp(argv[1], "help") == 0) {
			ipmi_fru_internaluse_help();
			return 0;
		}

		if ( (argc >= 3) && (!strncmp(argv[2], "info", 4)) ) {

			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			rc = ipmi_fru_info_internal_use(intf, fru_id);
		}
		else if ( (argc >= 3) && (!strncmp(argv[2], "print", 5)) ) {

			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			rc = ipmi_fru_read_internal_use(intf, fru_id, NULL);
		}
		else if ( (argc >= 4) && (!strncmp(argv[2], "read", 4)) ) {

			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			/* There is a file name in the parameters */
			if (is_valid_filename(argv[3]) != 0)
				return -1;

			lprintf(LOG_DEBUG, "FRU ID           : %d", fru_id);
			lprintf(LOG_DEBUG, "FRU File         : %s", argv[3]);

			rc = ipmi_fru_read_internal_use(intf, fru_id, argv[3]);
		}
		else if ( (argc >= 4) && (!strncmp(argv[2], "write", 5)) ) {

			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			/* There is a file name in the parameters */
			if (is_valid_filename(argv[3]) != 0)
				return -1;

			lprintf(LOG_DEBUG, "FRU ID           : %d", fru_id);
			lprintf(LOG_DEBUG, "FRU File         : %s", argv[3]);

			rc = ipmi_fru_write_internal_use(intf, fru_id, argv[3]);
		} else {
			lprintf(LOG_ERR,
					"Either unknown command or not enough parameters given.");
			ipmi_fru_internaluse_help();
			return -1;
		}
	}
	else if (!strncmp(argv[0], "edit", 4)) {
		if (argc > 1 && strcmp(argv[1], "help") == 0) {
			ipmi_fru_edit_help();
			return 0;
		} else if (argc < 2) {
			lprintf(LOG_ERR, "Not enough parameters given.");
			ipmi_fru_edit_help();
			return -1;
		}
		
		if (argc >= 2) {
			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			if (verbose) {
				printf("FRU ID           : %d\n", fru_id);
			}
		} else {
			printf("Using default FRU ID: %d\n", fru_id);
		}

		if (argc >= 3) {
			if (!strncmp(argv[2], "field", 5)) {
				if (argc != 6) {
					lprintf(LOG_ERR, "Not enough parameters given.");
					ipmi_fru_edit_help();
					return -1;
				}
				rc = ipmi_fru_set_field_string(intf, fru_id, *argv[3], *argv[4],
						(char *) argv[5]);
			} else if (!strncmp(argv[2], "oem", 3)) {
				rc = ipmi_fru_edit_multirec(intf, fru_id, argc, argv);
			} else {
				lprintf(LOG_ERR, "Invalid command: %s", argv[2]);
				ipmi_fru_edit_help();
				return -1;
			}
		} else {
			rc = ipmi_fru_edit_multirec(intf, fru_id, argc, argv);
		}
	}
	else if (!strncmp(argv[0], "get", 4)) {
		if (argc > 1 && (strncmp(argv[1], "help", 4) == 0)) {
			ipmi_fru_get_help();
			return 0;
		} else if (argc < 2) {
			lprintf(LOG_ERR, "Not enough parameters given.");
			ipmi_fru_get_help();
			return -1;
		}

		if (argc >= 2) {
			if (is_fru_id(argv[1], &fru_id) != 0)
				return -1;

			if (verbose) {
				printf("FRU ID           : %d\n", fru_id);
			}
		} else {
			printf("Using default FRU ID: %d\n", fru_id);
		}

		if (argc >= 3) {
			if (!strncmp(argv[2], "oem", 3)) {
				rc = ipmi_fru_get_multirec(intf, fru_id, argc, argv);
			} else {
				lprintf(LOG_ERR, "Invalid command: %s", argv[2]);
				ipmi_fru_get_help();
				return -1;
			}
		} else {
			rc = ipmi_fru_get_multirec(intf, fru_id, argc, argv);
		}
	}
	else {
		lprintf(LOG_ERR, "Invalid FRU command: %s", argv[0]);
		ipmi_fru_help();
		return -1;
	}

	return rc;
}