struct gt_gadget_create_data *dt;
int ind;
int c;
- int avaible_opts = GT_FORCE;
+ int avaible_opts = GT_FORCE | GT_HELP;
struct gt_setting *setting, *attrs = NULL;
_Bool iter;
int i;
goto out;
ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
- if (ind < 0)
+ if (ind < 0 || dt->opts & GT_HELP)
goto out;
if (ind == argc)
"\n"
"Options:\n"
" -f, --force\tDisable gadget if it was enabled\n"
- " -r, --recursive\tRemove configs and functions recursively\n",
+ " -r, --recursive\tRemove configs and functions recursively\n"
+ " -h, --help\tPrint this help\n",
program_name);
return -1;
}
{
struct gt_gadget_rm_data *dt;
int ind;
- int avaible_opts = GT_FORCE | GT_RECURSIVE;
+ int avaible_opts = GT_FORCE | GT_RECURSIVE | GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
- if (ind < 0)
+ if (ind < 0 || dt->opts & GT_HELP)
goto out;
if (argc - ind != 1)
{
struct gt_gadget_get_data *dt = NULL;
int i;
+ int ind;
+ int avaible_opts = GT_HELP;
if (argc == 0)
goto out;
if (dt == NULL)
goto out;
- dt->name = argv[0];
- dt->attrs = calloc(argc, sizeof(char *));
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
+ goto out;
+
+ dt->name = argv[ind++];
+ dt->attrs = calloc(argc - ind + 1, sizeof(char *));
if (dt->attrs == NULL)
goto out;
- argv++;
- for (i = 0; i < argc; i++) {
- dt->attrs[i] = argv[i];
- }
+ i = 0;
+ while (argv[ind])
+ dt->attrs[i++] = argv[ind++];
executable_command_set(exec, GET_EXECUTABLE(get), (void *)dt,
gt_gadget_get_destructor);
{
struct gt_gadget_set_data *dt = NULL;
int tmp;
-
- if (argc < 2)
- goto out;
+ int ind;
+ int avaible_opts = GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
- dt->name = argv[0];
- tmp = gt_parse_setting_list(&dt->attrs, argc-1, argv+1);
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
+ goto out;
+
+ if (argc - ind < 2)
+ goto out;
+
+ dt->name = argv[ind++];
+ tmp = gt_parse_setting_list(&dt->attrs, argc - ind, argv + ind);
if (tmp < 0)
goto out;
char **argv, ExecutableCommand *exec, void * data)
{
struct gt_gadget_enable_data *dt;
+ int ind;
+ int avaible_opts = GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
- switch (argc) {
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
+ goto out;
+
+ switch (argc - ind) {
case 1:
- dt->gadget = argv[0];
+ dt->gadget = argv[ind++];
break;
case 2:
- dt->gadget = argv[0];
- dt->udc = argv[1];
+ dt->gadget = argv[ind++];
+ dt->udc = argv[ind++];
break;
default:
goto out;
char c;
struct option opts[] = {
{"udc", required_argument, 0, 'u'},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
argc++;
while (1) {
int opt_index = 0;
- c = getopt_long(argc, argv, "u:", opts, &opt_index);
+ c = getopt_long(argc, argv, "u:h", opts, &opt_index);
if (c == -1)
break;
switch (c) {
case 'u':
dt->udc = optarg;
break;
+ case 'h':
+ goto out;
+ break;
default:
goto out;
}
{
struct gt_gadget_gadget_data *dt;
int ind;
- int avaible_opts = GT_RECURSIVE | GT_VERBOSE;
+ int avaible_opts = GT_RECURSIVE | GT_VERBOSE | GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
- if (ind < 0)
+ if (ind < 0 || dt->opts & GT_HELP)
goto out;
switch (argc - ind) {
{"file", required_argument, 0, 1},
{"stdin", no_argument, 0, 2},
{"path", required_argument, 0, 3},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
argc++;
while (1) {
int opt_index = 0;
- c = getopt_long(argc, argv, "o", opts, &opt_index);
+ c = getopt_long(argc, argv, "oh", opts, &opt_index);
if (c == -1)
break;
switch (c) {
goto out;
dt->path = optarg;
break;
+ case 'h':
+ goto out;
+ break;
default:
goto out;
}
{"file", required_argument, 0, 1},
{"stdout", no_argument, 0, 2},
{"path", required_argument, 0, 3},
+ {"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
argc++;
while (1) {
int opt_index = 0;
- c = getopt_long(argc, argv, "f", opts, &opt_index);
+ c = getopt_long(argc, argv, "fh", opts, &opt_index);
if (c == -1)
break;
switch (c) {
goto out;
dt->path = optarg;
break;
+ case 'h':
+ goto out;
+ break;
default:
goto out;
}
{
int ind;
struct gt_gadget_template_data *dt;
- int avaible_opts = GT_VERBOSE | GT_RECURSIVE;
+ int avaible_opts = GT_VERBOSE | GT_RECURSIVE | GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
+
ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
- if (ind < 0)
+ if (ind < 0 || dt->opts & GT_HELP)
goto out;
if (argc - ind > 1)
static void gt_parse_gadget_template_rm(const Command *cmd, int argc,
char **argv, ExecutableCommand *exec, void * data)
{
- const char *dt = NULL;
+ struct gt_gadget_template_rm_data *dt = NULL;
+ int ind;
+ int avaible_opts = GT_HELP;
+
+ dt = zalloc(sizeof(*dt));
+ if (dt == NULL)
+ goto out;
+
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
+ goto out;
- if (argc != 1)
+ if (argc - ind != 1)
goto out;
- dt = argv[0];
+ dt->name = argv[ind++];
executable_command_set(exec, GET_EXECUTABLE(template_rm), (void *)dt,
NULL);
{
int tmp;
struct gt_gadget_template_set_data *dt;
+ int ind;
+ int avaible_opts = GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
- if (argc != 2)
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
+ goto out;
+
+ if (argc - ind != 2)
goto out;
- dt->name = argv[0];
- tmp = gt_parse_setting_list(&dt->attr, argc-1, argv+1);
+ dt->name = argv[ind++];
+ tmp = gt_parse_setting_list(&dt->attr, argc - ind, argv + ind);
if (tmp < 0)
goto out;
{
int i;
struct gt_gadget_template_get_data *dt;
+ int ind;
+ int avaible_opts = GT_HELP;
dt = zalloc(sizeof(*dt));
if (dt == NULL)
goto out;
- if (argc < 1)
+ ind = gt_get_options(&dt->opts, avaible_opts, argc, argv);
+ if (ind < 0 || dt->opts & GT_HELP)
goto out;
- dt->name = argv[0];
+ if (argc - ind < 1)
+ goto out;
+
+ dt->name = argv[ind++];
dt->attr = calloc(argc, sizeof(char *));
if (dt->attr == NULL)
goto out;
- argv++;
- argc--;
- for (i = 0; i < argc; i++)
- dt->attr[i] = argv[i];
+ i = 0;
+ while (argv[ind])
+ dt->attr[i++] = argv[ind++];
executable_command_set(exec, GET_EXECUTABLE(get), (void *)dt,
gt_gadget_template_get_destructor);