Skip to content

Commit

Permalink
export: allow opts without directory name
Browse files Browse the repository at this point in the history
allow `uv --record=limit=3:exit_on_limit` (using autmoatic directory export.<date>)
  • Loading branch information
MartinPulec committed Jul 1, 2024
1 parent 0a0b14e commit 894bd3a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ static void usage() {
color_printf(TERM_BOLD "\tpaused" TERM_RESET " - use specified directory but do not export immediately (can be started with a key or through control socket)\n");
}

static bool parse_options(struct exporter *s, char *save_ptr, bool *should_export) {
static bool
parse_options(struct exporter *s, const char *ccfg, bool *should_export)
{
char buf[STR_LEN];
snprintf(buf, sizeof buf, "%s", ccfg);
char *cfg = buf;
char *save_ptr = NULL;
char *item = NULL;
while ((item = strtok_r(NULL, ":", &save_ptr)) != NULL) {
while ((item = strtok_r(cfg, ":", &save_ptr)) != NULL) {
if (strstr(item, "help") == item) {
usage();
return false;
Expand All @@ -124,10 +130,13 @@ static bool parse_options(struct exporter *s, char *save_ptr, bool *should_expor
}
} else if (strcmp(item, "exit_on_limit") == 0) {
s->exit_on_limit = true;
} else if (s->dir == NULL && cfg != NULL) {
s->dir = strdup(item);
} else {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Wrong option: %s!\n", item);
return false;
}
cfg = NULL;
}
return true;
}
Expand All @@ -146,13 +155,7 @@ struct exporter *export_init(struct module *parent, const char *cfg, bool should
export_destroy(s);
return NULL;
}
s->dir = strdup(cfg);
char *save_ptr = NULL;
char *item = strtok_r(s->dir, ":", &save_ptr); // skip the dir
if (item == NULL) {
HANDLE_ERROR
}
if (!parse_options(s, save_ptr, &should_export)) {
if (!parse_options(s, cfg, &should_export)) {
HANDLE_ERROR
}
} else {
Expand Down

0 comments on commit 894bd3a

Please sign in to comment.