Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit 6ca94a6

Browse files
committed
target: moved target command to own file
1 parent c8dffb9 commit 6ca94a6

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

src/bin/bmputil-cli/cli_commands/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ use directories::ProjectDirs;
1010
use log::error;
1111

1212
use crate::cli_commands::probe::ProbeArguments;
13+
use crate::cli_commands::target::TargetCommmands;
1314
use crate::{CliArguments, CompletionArguments};
1415

1516
pub mod probe;
17+
mod target;
1618

1719
#[derive(Subcommand)]
1820
pub enum ToplevelCommmands
1921
{
2022
/// Actions to be performed against a probe
2123
Probe(ProbeArguments),
2224
/// Actions to be performed against a target connected to a probe
23-
Target,
25+
#[command(subcommand)]
26+
Target(TargetCommmands),
2427
/// Actions that run the tool as a debug/tracing server
2528
Server,
2629
/// Actions that run debugging commands against a target connected to a probe
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use bmputil::bmp::BmpMatcher;
2+
use clap::Subcommand;
3+
use color_eyre::eyre::Result;
4+
use log::info;
5+
6+
use crate::CliArguments;
7+
8+
#[derive(Subcommand)]
9+
#[command(arg_required_else_help(true))]
10+
pub enum TargetCommmands
11+
{
12+
/// Print information about the target power control state
13+
Power,
14+
}
15+
16+
impl TargetCommmands
17+
{
18+
pub fn subcommand(&self, cli_args: &CliArguments) -> Result<()>
19+
{
20+
match self {
21+
TargetCommmands::Power => power_command(&cli_args),
22+
}
23+
}
24+
}
25+
26+
fn power_command(cli_args: &CliArguments) -> Result<()>
27+
{
28+
// Try and identify all the probes on the system that are allowed by the invocation
29+
let matcher = BmpMatcher::from_params(cli_args);
30+
let mut results = matcher.find_matching_probes();
31+
32+
// Otherwise, turn the result set into a list and go through them displaying them
33+
let device = results.pop_single("power").map_err(|kind| kind.error())?;
34+
let remote = device.bmd_serial_interface()?.remote()?;
35+
36+
let power = remote.get_target_power_state()?;
37+
38+
info!("Device target power state: {}", power);
39+
40+
Ok(())
41+
}

src/bin/bmputil-cli/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,7 @@ fn main() -> Result<()>
244244

245245
match &cli_args.subcommand {
246246
ToplevelCommmands::Probe(probe_args) => probe_args.subcommand(&cli_args),
247-
ToplevelCommmands::Target => {
248-
warn!("Command space reserved for future tool version");
249-
Ok(())
250-
},
247+
ToplevelCommmands::Target(target_commands) => target_commands.subcommand(&cli_args),
251248
ToplevelCommmands::Server => {
252249
warn!("Command space reserved for future tool version");
253250
Ok(())

0 commit comments

Comments
 (0)