ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_cli.h File Reference

Command-line parsing for the mdl CLI. More...

#include <stddef.h>
#include <stdint.h>
#include "mdl_app.h"
#include "ra8_io_stream.h"
Include dependency graph for mdl_cli.h:
This graph shows which files directly or indirectly include this file:

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.

Detailed Description

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.

Enumeration Type Documentation

◆ mdl_cli_mode_t

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.

Since
0.1.0
Enumerator
k_mdl_cli_mode_invalid 

No valid primary mode.

k_mdl_cli_mode_series 

Download or update one configured series.

k_mdl_cli_mode_search 

Search a descriptor and optionally pick.

k_mdl_cli_mode_browse 

Browse a descriptor and optionally pick.

k_mdl_cli_mode_list 

List tracked local series.

k_mdl_cli_mode_update_all 

Update every tracked local series.

k_mdl_cli_mode_remove 

Remove one tracked local series.

k_mdl_cli_mode_verify 

Verify tracked state/pages/containers.

k_mdl_cli_mode_init_site 

Generate a starter descriptor template.

k_mdl_cli_mode_pack 

Package a local page-image directory.

k_mdl_cli_mode_artifact 

Download one verified HTTPS artifact.

k_mdl_cli_mode_page 

Debug-download images from one page URL.

k_mdl_cli_mode_help 

Print command help without running a mode.

k_mdl_cli_mode_version 

Print the program version and exit.

Definition at line 31 of file mdl_cli.h.

Function Documentation

◆ mdl_cli_mode_name()

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".

Parameters
[in]modeMode value.
Returns
Pointer to a process-lifetime static mode name.
Return values
non-NULLA stable name, or "invalid" for an unknown value.
Precondition
mode is any value representable by mdl_cli_mode_t.
The caller treats the returned bytes as read-only.
Postcondition
The returned string is NUL-terminated.
No caller-visible state is modified.
Note
Thread-safe: reads immutable static storage only.
Since
0.1.0

Definition at line 415 of file mdl_cli.c.

Referenced by internal_validate_allowed_args().

◆ mdl_cli_parse()

void mdl_cli_parse ( int argc,
char ** argv,
mdl_args_t * a )

Parse argv into a; numeric fields stay as strings for main.

Parameters
[in]argcArgument count.
[in]argvArgument vector.
[out]aParsed options; a->bad is set on any unknown argument.
Returns
Nothing.
Precondition
argv holds argc entries; a is non-NULL.
a was zero-initialised (defaults applied) before the call.
Postcondition
Every recognised option is recorded in a.
a->bad reflects whether an argument was unrecognised.
Note
Not thread-safe: writes caller storage.
Since
0.1.0

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().

◆ mdl_cli_parse_nums()

ra8_err_t mdl_cli_parse_nums ( const mdl_args_t * a,
ra8_io_stream_t * diagnostic,
mdl_nums_t * n )
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.

Parameters
[in]aParsed command-line options (never NULL).
[in,out]diagnosticBound stream receiving any rejection diagnostic.
[out]nReceives the validated scalars (never NULL).
Returns
Canonical validation or stream status.
Return values
k_ra8_okAll fields are valid and n is fully populated.
k_ra8_err_invalid_argA field is invalid and its complete diagnostic was written.
k_ra8_err_null_ptrA required pointer was null.
otherThe injected stream rejected a diagnostic write.
Precondition
a, diagnostic, and n are non-NULL; a was populated by mdl_cli_parse.
The caller maps k_ra8_err_invalid_arg to the usage exit code.
Postcondition
On success, n->chapters >= 1 and every scalar reflects the args.
On failure, n is left byte-for-byte unchanged.
Note
Thread-safe across distinct output objects and streams.
Since
0.1.0

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_cli_run_opts()

mdl_run_opts_t mdl_cli_run_opts ( const mdl_args_t * a)

Fold parsed args into the cross-cutting run options.

Parameters
[in]aParsed command-line options.
Returns
The assembled run options (network policy + identity/politeness).
Return values
mdl_run_opts_tA value with the policy and knobs set from a.
Precondition
a is non-NULL.
a was populated by mdl_cli_parse.
Postcondition
The returned policy has the size cap defaulted when --max-bytes was absent.
Note
Thread-safe: depends only on its argument.
Since
0.1.0

Uses caller-owned fixed-capacity argument state without allocation. Mode selection and numeric publication remain explicit validation phases.

Postcondition
Documented outputs and the return value describe the same outcome.

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().

◆ mdl_cli_usage()

ra8_err_t mdl_cli_usage ( ra8_io_stream_t * diagnostic,
const char * a0 )
nodiscard

Write the complete usage block to an injected byte stream.

Parameters
[in,out]diagnosticBound stream receiving the help text.
[in]a0argv[0], the program name shown in the usage lines.
Returns
Canonical stream status.
Return values
k_ra8_okThe complete usage block was accepted.
k_ra8_err_null_ptrA required pointer was null.
otherThe injected stream rejected a write.
Precondition
diagnostic is bound and exclusively owned for the call.
a0 is a NUL-terminated string.
Postcondition
Success writes the exact complete usage block.
Failure stops at the first rejected stream operation.
Note
Thread-safe across distinct streams.
Since
0.1.0

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().

◆ mdl_cli_validate()

ra8_err_t mdl_cli_validate ( const mdl_args_t * a,
ra8_io_stream_t * diagnostic,
mdl_cli_mode_t * mode )
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.

Parameters
[in]aParsed, pre-default argument set.
[in,out]diagnosticBound stream receiving any rejection diagnostic.
[out]modeReceives the one selected command mode on success.
Returns
Canonical validation or stream status.
Return values
k_ra8_okValidation succeeded and mode names the command.
k_ra8_err_invalid_argThe invocation is invalid and its complete diagnostic was written.
k_ra8_err_null_ptrA required pointer was null.
otherThe injected stream rejected a diagnostic write.
Precondition
a, diagnostic, and mode are non-NULL and mdl_cli_parse has run.
Defaults that were absent on the command line have not been injected.
Postcondition
On success, mode is not k_mdl_cli_mode_invalid.
On failure, mode is k_mdl_cli_mode_invalid.
Note
Thread-safe across distinct output objects and streams.
Since
0.1.0

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().