MRTKLIB
0.7.14
Modernized GNSS Positioning Library
Loading...
Searching...
No Matches
mrtk_cli.h
Go to the documentation of this file.
1
/*------------------------------------------------------------------------------
2
* mrtk_cli.h : shared CLI helpers for mrtk subcommands
3
*
4
* Copyright (C) 2026, MRTKLIB Contributors, All rights reserved.
5
*
6
* SPDX-License-Identifier: BSD-2-Clause
7
*
8
* description : Small utilities used by every `mrtk <subcommand>` entry point
9
* to keep CLI surface (long-option aliases, help-flag detection)
10
* consistent without rewriting per-subcommand argument parsers.
11
*-----------------------------------------------------------------------------*/
12
#ifndef MRTK_CLI_H
13
#define MRTK_CLI_H
14
15
#ifdef __cplusplus
16
extern
"C"
{
17
#endif
18
19
/**
20
* @brief Long-option to short-option alias entry.
21
*
22
* Each subcommand defines a NULL-terminated array of these to declare which
23
* `--long` flags translate to which `-short` flag in its existing parser. Used
24
* by mrtk_normalize_args() as a pre-pass over argv.
25
*/
26
typedef
struct
{
27
const
char
*
long_opt
;
/**< long-form flag, e.g. "--config" */
28
const
char
*
short_opt
;
/**< short-form flag the parser already handles, e.g. "-k" */
29
}
mrtk_optmap_t
;
30
31
/**
32
* @brief Translate `--long` flags to their `-short` aliases in argv (in place).
33
*
34
* Walks argv[1..argc-1] and, for each entry that exactly matches a
35
* `map[i].long_opt`, swaps the pointer to point at `map[i].short_opt` instead.
36
* Only the argv pointers are reassigned; the underlying argument strings are
37
* never mutated. argv[0] is left untouched. Pass NULL or an empty map to no-op.
38
*
39
* @param[in] argc argument count
40
* @param[in,out] argv argument vector (pointers may be reassigned)
41
* @param[in] map NULL-terminated alias table (terminator: {NULL, NULL})
42
*/
43
void
mrtk_normalize_args
(
int
argc,
char
** argv,
const
mrtk_optmap_t
* map);
44
45
/**
46
* @brief Returns 1 if `arg` is a generic help flag (`-h` or `--help`), else 0.
47
*
48
* Subcommands that have repurposed `-h` (e.g. `post` uses it for fix-and-hold
49
* AR) must NOT use this helper and should match `--help` (and any historical
50
* short flag like `-?`) manually.
51
*
52
* @param[in] arg argument string (must not be NULL)
53
*/
54
int
mrtk_is_help_flag
(
const
char
* arg);
55
56
#ifdef __cplusplus
57
}
58
#endif
59
60
#endif
/* MRTK_CLI_H */
mrtk_normalize_args
void mrtk_normalize_args(int argc, char **argv, const mrtk_optmap_t *map)
Translate --long flags to their -short aliases in argv (in place).
Definition
mrtk_cli.c:12
mrtk_is_help_flag
int mrtk_is_help_flag(const char *arg)
Returns 1 if arg is a generic help flag (-h or --help), else 0.
Definition
mrtk_cli.c:30
mrtk_optmap_t
Long-option to short-option alias entry.
Definition
mrtk_cli.h:26
mrtk_optmap_t::short_opt
const char * short_opt
Definition
mrtk_cli.h:28
mrtk_optmap_t::long_opt
const char * long_opt
Definition
mrtk_cli.h:27
include
mrtklib
mrtk_cli.h
Generated by
1.15.0