|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Command-line parsing for the mdl CLI. More...
Go to the source code of this file.
Data Structures | |
| struct | mdl_args_t |
| Parsed command-line options in string form (converted by main). More... | |
| struct | mdl_nums_t |
| The validated numeric CLI scalars, parsed once before any run mode. More... | |
Enumerations | |
| enum | mdl_cli_mode_t : uint8_t { k_mdl_cli_mode_invalid = 0 , k_mdl_cli_mode_series , k_mdl_cli_mode_search , k_mdl_cli_mode_browse , k_mdl_cli_mode_list , k_mdl_cli_mode_update_all , k_mdl_cli_mode_remove , k_mdl_cli_mode_verify , k_mdl_cli_mode_init_site , k_mdl_cli_mode_pack , k_mdl_cli_mode_artifact , k_mdl_cli_mode_page , k_mdl_cli_mode_help , k_mdl_cli_mode_version } |
| Exactly one command mode selected by a valid invocation. More... | |
Functions | |
| ra8_err_t | mdl_cli_usage (ra8_io_stream_t *diagnostic, const char *a0) |
| Write the complete usage block to an injected byte stream. | |
| void | mdl_cli_parse (int argc, char **argv, mdl_args_t *a) |
| Parse argv into a; numeric fields stay as strings for main. | |
| mdl_run_opts_t | mdl_cli_run_opts (const mdl_args_t *a) |
| Fold parsed args into the cross-cutting run options. | |
| ra8_err_t | mdl_cli_parse_nums (const mdl_args_t *a, ra8_io_stream_t *diagnostic, mdl_nums_t *n) |
| Strictly parse and validate every numeric CLI field. | |
| ra8_err_t | mdl_cli_validate (const mdl_args_t *a, ra8_io_stream_t *diagnostic, mdl_cli_mode_t *mode) |
| Validate mode selection, required arguments, and per-mode options. | |
| const char * | mdl_cli_mode_name (mdl_cli_mode_t mode) |
| Stable human-readable command mode name. | |
Command-line parsing for the mdl CLI.
Splits argv handling out of main.c: the raw option strings land in mdl_args_t, and the cross-cutting security/politeness knobs are folded into the portable mdl_run_opts_t the application layer already consumes. Numeric fields stay as strings so main owns their conversion and defaulting. Nothing here is reachable from the downloader itself – the translation from these argv-shaped values into the ones ::mdl_app.h names happens once, in mdl_compose.c.
Definition in file mdl_cli.h.
| enum mdl_cli_mode_t : uint8_t |
Exactly one command mode selected by a valid invocation.
Values are stable dispatch identities produced by mdl_cli_validate; callers must not infer modes from option precedence.
| const char * mdl_cli_mode_name | ( | mdl_cli_mode_t | mode | ) |
Stable human-readable command mode name.
Provides the spelling used in diagnostics without exposing a mutable name table to callers. Unknown values map to "invalid".
| [in] | mode | Mode value. |
| non-NULL | A stable name, or "invalid" for an unknown value. |
mode is any value representable by mdl_cli_mode_t. Definition at line 415 of file mdl_cli.c.
Referenced by internal_validate_allowed_args().
| void mdl_cli_parse | ( | int | argc, |
| char ** | argv, | ||
| mdl_args_t * | a ) |
Parse argv into a; numeric fields stay as strings for main.
| [in] | argc | Argument count. |
| [in] | argv | Argument vector. |
| [out] | a | Parsed options; a->bad is set on any unknown argument. |
Uses caller-owned fixed-capacity argument state without allocation. Mode selection and numeric publication remain explicit validation phases.
Definition at line 278 of file mdl_cli.c.
References internal_parse_bool_flags(), internal_parse_positional_or_bad(), internal_parse_value_opt(), and internal_parse_verify_opt().
Referenced by internal_main_init().
|
nodiscard |
Strictly parse and validate every numeric CLI field.
Converts the string-form numeric options (--timeout, --chapters, --max, --seed, --from, and --max-bytes for presence-validation) into typed scalars, rejecting any non-numeric or trailing-garbage value with a usage message on the injected diagnostic stream rather than substituting 0. Decimal chapter values such as 108.5 are accepted for --from; NaN and infinity are not. --chapters of 0 is rejected.
| [in] | a | Parsed command-line options (never NULL). |
| [in,out] | diagnostic | Bound stream receiving any rejection diagnostic. |
| [out] | n | Receives the validated scalars (never NULL). |
| k_ra8_ok | All fields are valid and n is fully populated. |
| k_ra8_err_invalid_arg | A field is invalid and its complete diagnostic was written. |
| k_ra8_err_null_ptr | A required pointer was null. |
| other | The injected stream rejected a diagnostic write. |
a, diagnostic, and n are non-NULL; a was populated by mdl_cli_parse. n is left byte-for-byte unchanged.Definition at line 421 of file mdl_cli_nums.c.
References mdl_cli_raw_nums_t::chapters, mdl_nums_t::chapters, internal_cli_parse_chapter_pick(), internal_cli_parse_num_values(), internal_cli_validate_num_ranges(), k_ra8_err_null_ptr, k_ra8_ok, mdl_cli_raw_nums_t::max_imgs, mdl_nums_t::max_imgs, mdl_cli_raw_nums_t::pick, mdl_nums_t::pick, mdl_cli_raw_nums_t::timeout, and mdl_nums_t::timeout.
Referenced by main().
| mdl_run_opts_t mdl_cli_run_opts | ( | const mdl_args_t * | a | ) |
Fold parsed args into the cross-cutting run options.
| [in] | a | Parsed command-line options. |
| mdl_run_opts_t | A value with the policy and knobs set from a. |
Uses caller-owned fixed-capacity argument state without allocation. Mode selection and numeric publication remain explicit validation phases.
Definition at line 862 of file mdl_cli.c.
References mdl_args_t::allow_incomplete, mdl_args_t::allow_private, mdl_args_t::contact, mdl_args_t::cross_host, mdl_args_t::ignore_robots, k_cli_dec_base, k_max_response_bytes_def, mdl_args_t::max_bytes, mdl_args_t::polite, mdl_args_t::progress, mdl_args_t::proxy, mdl_args_t::refetch, and mdl_args_t::socks5.
Referenced by main().
|
nodiscard |
Write the complete usage block to an injected byte stream.
| [in,out] | diagnostic | Bound stream receiving the help text. |
| [in] | a0 | argv[0], the program name shown in the usage lines. |
| k_ra8_ok | The complete usage block was accepted. |
| k_ra8_err_null_ptr | A required pointer was null. |
| other | The injected stream rejected a write. |
diagnostic is bound and exclusively owned for the call. a0 is a NUL-terminated string. Definition at line 153 of file mdl_cli_usage.c.
References internal_cli_usage_actions(), internal_cli_usage_discovery(), internal_cli_usage_network_options(), k_ra8_err_null_ptr, k_ra8_ok, and priv_mdl_cli_put_parts().
Referenced by main().
|
nodiscard |
Validate mode selection, required arguments, and per-mode options.
Enforces exactly one primary command, rejects duplicate/unknown options recorded by mdl_cli_parse, and uses a per-mode allowlist so an accepted option always has an effect. Proxy escape hatches and debug image attributes receive their mode-independent consistency checks here.
| [in] | a | Parsed, pre-default argument set. |
| [in,out] | diagnostic | Bound stream receiving any rejection diagnostic. |
| [out] | mode | Receives the one selected command mode on success. |
| k_ra8_ok | Validation succeeded and mode names the command. |
| k_ra8_err_invalid_arg | The invocation is invalid and its complete diagnostic was written. |
| k_ra8_err_null_ptr | A required pointer was null. |
| other | The injected stream rejected a diagnostic write. |
a, diagnostic, and mode are non-NULL and mdl_cli_parse has run. mode is not k_mdl_cli_mode_invalid. mode is k_mdl_cli_mode_invalid.Definition at line 832 of file mdl_cli.c.
References mdl_args_t::bad, internal_cli_invalid(), internal_resolve_mode(), internal_validate_allowed_args(), internal_validate_mode_fields(), internal_validate_network_args(), k_mdl_cli_mode_invalid, k_ra8_err_null_ptr, and k_ra8_ok.
Referenced by main().