Expand description
Shared command-line handling for the Rust tag tools.
Port of host/commandline/options.cc and the parts of log.c the tools
rely on. Every tool that talks to a tag flattens BaseArgs into its own
arguments, calls init_logging, then select_base to find the
ST-LINK, exactly as the C++ tools call parse_options():
-d/--debuglogs at DEBUG; otherwise only errors are logged.-b/--base bus:devicepicks a base. It is required when more than one ST-LINK is connected; with none connected the tool exits.
Log lines go to stderr as HH:MM:SS LEVEL file:line: message, the
format of log.c.
Selecting a base touches no hardware beyond USB enumeration; it is the
tool’s later Tag::attach that resets the tag.
§Examples
The skeleton every tool follows (Cli is the tool’s own clap parser):
use clap::Parser;
use tag_tools::{BaseArgs, init_logging, select_base};
use tagcore::Tag;
#[derive(Parser)]
struct Cli {
#[command(flatten)]
base: BaseArgs,
}
let cli = Cli::parse();
init_logging(&cli.base);
let tag = Tag::new();
let dev = select_base::<Cli>(&tag, &cli.base);
if !tag.attach(&dev) {
std::process::exit(1);
}Structs§
- Base
Args - The options every tag tool shares (
options.cc).
Functions§
- enum_
name - The protobuf name of an enum value of type
E, or its number. - exit_
on_ interrupt - Exits with status 1 on Ctrl-C, as the C++ tools’ SIGINT handler does.
- init_
logging - Starts logging to stderr in the
log.cformat, at DEBUG with--debugand at ERROR otherwise. - init_
logging_ at - Starts logging to stderr in the
log.cformat atlevel. - parse_
bus_ device - Parses
bus:deviceassscanf("%u:%u")would, into USB bus and address. - select_
base - Finds the ST-LINK the arguments select, or exits.
- set_
log_ level - Changes the log level after
init_logging, aslog_set_level()does. - state_
name - The protobuf name of a tag state number, such as
"IDLE", or the number itself when it has no name, asTagState_Name()prints it.