Skip to content

Commit 69b1f64

Browse files
committed
Working on refactoring command stuff
1 parent 1292eed commit 69b1f64

70 files changed

Lines changed: 630 additions & 1186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/auxflash/src/lib.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use anyhow::Result;
1313
use clap::{CommandFactory, Parser};
1414
use colored::Colorize;
1515
use humility_cli::ExecutionContext;
16-
use humility_cmd::CommandKind;
1716

1817
use humility_auxflash::AuxFlashHandler;
19-
use humility_cmd::{Archive, Attach, Command, Validate};
18+
use humility_cmd::Command;
2019

2120
#[derive(Parser, Debug)]
2221
#[clap(name = "auxflash", about = env!("CARGO_PKG_DESCRIPTION"))]
@@ -99,9 +98,9 @@ fn auxflash_status(mut worker: AuxFlashHandler, verbose: bool) -> Result<()> {
9998
}
10099

101100
fn auxflash(context: &mut ExecutionContext) -> Result<()> {
102-
let core = &mut **context.core.as_mut().unwrap();
103101
let subargs = AuxFlashArgs::try_parse_from(&context.cli.cmd)?;
104-
let hubris = context.archive.as_ref().unwrap();
102+
let hubris = &context.cli.archive()?;
103+
let core = &mut *context.cli.attach_live_booted(hubris)?;
105104
let mut worker = AuxFlashHandler::new(hubris, core, subargs.timeout)?;
106105

107106
match subargs.cmd {
@@ -132,14 +131,5 @@ fn auxflash(context: &mut ExecutionContext) -> Result<()> {
132131
}
133132

134133
pub fn init() -> Command {
135-
Command {
136-
app: AuxFlashArgs::command(),
137-
name: "auxflash",
138-
run: auxflash,
139-
kind: CommandKind::Attached {
140-
archive: Archive::Required,
141-
attach: Attach::LiveOnly,
142-
validate: Validate::Booted,
143-
},
144-
}
134+
Command { app: AuxFlashArgs::command(), name: "auxflash", run: auxflash }
145135
}

cmd/console-proxy/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::PathBuf;
1010

1111
use clap::{CommandFactory, Parser};
1212

13-
use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
13+
use humility_cmd::Command;
1414

1515
#[cfg(not(windows))]
1616
mod posix;
@@ -113,10 +113,5 @@ pub fn init() -> Command {
113113
app: UartConsoleArgs::command(),
114114
name: "console-proxy",
115115
run: console_proxy,
116-
kind: CommandKind::Attached {
117-
archive: Archive::Required,
118-
attach: Attach::LiveOnly,
119-
validate: Validate::Booted,
120-
},
121116
}
122117
}

cmd/console-proxy/src/posix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ impl UnrawTermiosGuard {
314314
}
315315

316316
pub(super) fn console_proxy(context: &mut ExecutionContext) -> Result<()> {
317-
let core = &mut **context.core.as_mut().unwrap();
318317
let subargs = UartConsoleArgs::try_parse_from(&context.cli.cmd)?;
319-
let hubris = context.archive.as_ref().unwrap();
318+
let hubris = &context.cli.archive()?;
319+
let core = &mut *context.cli.attach_live_booted(hubris)?;
320320
let mut worker = UartConsoleHandler::new(
321321
hubris,
322322
core,

cmd/counters/src/lib.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ use humility::core::Core;
206206
use humility::hubris::*;
207207
use humility::reflect::{self, Load, Value};
208208
use humility_cli::ExecutionContext;
209-
use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
209+
use humility_cmd::Command;
210210
use humility_doppel::{CountedRingbuf, CounterVariant, Counters};
211211
use indexmap::IndexMap;
212212
use std::collections::BTreeMap;
@@ -324,12 +324,11 @@ const LIST_HINT: &str = "use `humility counters list` to list all \
324324
available counters";
325325

326326
fn counters(context: &mut ExecutionContext) -> Result<()> {
327-
let core = &mut **context.core.as_mut().unwrap();
328-
let hubris = context.archive.as_ref().unwrap();
329-
327+
let hubris = &context.cli.archive()?;
330328
let subargs = CountersArgs::try_parse_from(&context.cli.cmd)?;
331329

332330
if let Some(Subcmd::Ipc(ipc)) = subargs.command {
331+
let core = &mut *context.cli.attach_live_or_dump_match(hubris)?;
333332
return ipc.ipc_counter_dump(hubris, core);
334333
}
335334
let name = subargs.name();
@@ -428,6 +427,7 @@ fn counters(context: &mut ExecutionContext) -> Result<()> {
428427
}
429428

430429
let mut json: IndexMap<&str, IndexMap<_, _>> = IndexMap::new();
430+
let core = &mut *context.cli.attach_live_or_dump_match(hubris)?;
431431
for (t, ctrs) in counters {
432432
// Try not to use `?` here, because it causes one bad counter to make
433433
// them all unavailable. Instead, construct an iterator of
@@ -623,14 +623,5 @@ fn hint() -> impl std::fmt::Display {
623623
}
624624

625625
pub fn init() -> Command {
626-
Command {
627-
app: CountersArgs::command(),
628-
name: "counters",
629-
run: counters,
630-
kind: CommandKind::Attached {
631-
archive: Archive::Required,
632-
attach: Attach::Any,
633-
validate: Validate::Match,
634-
},
635-
}
626+
Command { app: CountersArgs::command(), name: "counters", run: counters }
636627
}

cmd/dashboard/src/lib.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use hif::*;
2929
use humility::core::Core;
3030
use humility::hubris::*;
3131
use humility_cli::ExecutionContext;
32-
use humility_cmd::{Archive, Attach, Command, CommandKind, Validate};
32+
use humility_cmd::Command;
3333
use humility_hiffy::*;
3434
use humility_idol::{self as idol, HubrisIdol};
3535
use ratatui::{
@@ -736,11 +736,10 @@ where
736736
}
737737

738738
fn dashboard(context: &mut ExecutionContext) -> Result<()> {
739-
let hubris = context.archive.as_ref().unwrap();
740-
741-
let core = &mut **context.core.as_mut().unwrap();
742-
743739
let subargs = DashboardArgs::try_parse_from(&context.cli.cmd)?;
740+
let hubris = &context.cli.archive()?;
741+
let core = &mut *context.cli.attach_live_booted(hubris)?;
742+
744743
let dashboard = Dashboard::new(hubris, core, &subargs)?;
745744

746745
// setup terminal
@@ -767,16 +766,7 @@ fn dashboard(context: &mut ExecutionContext) -> Result<()> {
767766
}
768767

769768
pub fn init() -> Command {
770-
Command {
771-
app: DashboardArgs::command(),
772-
name: "dashboard",
773-
run: dashboard,
774-
kind: CommandKind::Attached {
775-
archive: Archive::Required,
776-
attach: Attach::LiveOnly,
777-
validate: Validate::Booted,
778-
},
779-
}
769+
Command { app: DashboardArgs::command(), name: "dashboard", run: dashboard }
780770
}
781771

782772
fn sensor_ops(

cmd/debugmailbox/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use anyhow::{Context, Result, bail};
3232
use byteorder::{ByteOrder, LittleEndian, WriteBytesExt};
3333
use clap::{CommandFactory, Parser};
3434
use humility_cli::ExecutionContext;
35-
use humility_cmd::{Archive, Command, CommandKind};
35+
use humility_cmd::Command;
3636
use probe_rs::{
3737
DebugProbeError, DebugProbeSelector, Probe,
3838
architecture::arm::{ApAddress, ArmProbeInterface, DapError, DpAddress},
@@ -464,6 +464,5 @@ pub fn init() -> Command {
464464
app: DebugMailboxArgs::command(),
465465
name: "debugmailbox",
466466
run: debugmailboxcmd,
467-
kind: CommandKind::Unattached { archive: Archive::Ignored },
468467
}
469468
}

cmd/diagnose/src/lib.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,14 @@ use clap::{CommandFactory, Parser};
1919
use humility::core::Core;
2020
use humility::hubris::*;
2121
use humility_cli::ExecutionContext;
22-
use humility_cmd::CommandKind;
23-
use humility_cmd::{Archive, Attach, Command, Validate};
22+
use humility_cmd::Command;
2423
use humility_doppel::{GenOrRestartCount, Task, TaskDesc, TaskState};
2524
use std::num::NonZeroU32;
2625
use std::time::Duration;
2726

2827
/// Command registration.
2928
pub fn init() -> Command {
30-
Command {
31-
app: DiagnoseArgs::command(),
32-
name: "diagnose",
33-
run: diagnose,
34-
kind: CommandKind::Attached {
35-
archive: Archive::Required,
36-
attach: Attach::Any,
37-
validate: Validate::Booted,
38-
},
39-
}
29+
Command { app: DiagnoseArgs::command(), name: "diagnose", run: diagnose }
4030
}
4131

4232
#[derive(Parser, Debug)]
@@ -83,10 +73,9 @@ fn section(title: &str) {
8373
}
8474

8575
fn diagnose(context: &mut ExecutionContext) -> Result<()> {
86-
let core = &mut **context.core.as_mut().unwrap();
87-
let hubris = context.archive.as_ref().unwrap();
88-
8976
let subargs = DiagnoseArgs::try_parse_from(&context.cli.cmd)?;
77+
let hubris = &context.cli.archive()?;
78+
let core = &mut *context.cli.attach_live_booted(hubris)?;
9079

9180
section("Initial Inspection");
9281

cmd/discover/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use colored::Colorize;
4545
use hubpack::SerializedSize;
4646
use humility::net::decode_iface;
4747
use humility_cli::ExecutionContext;
48-
use humility_cmd::{Archive, Command, CommandKind};
48+
use humility_cmd::Command;
4949
use serde::{Deserialize, Serialize};
5050

5151
#[derive(Parser, Debug)]
@@ -313,9 +313,9 @@ fn discover_dump(seen: BTreeSet<Target>, image_id: Option<&[u8]>) {
313313

314314
fn discover_run(context: &mut ExecutionContext) -> Result<()> {
315315
let subargs = DiscoverArgs::try_parse_from(&context.cli.cmd)?;
316-
let hubris = context.archive.as_ref().unwrap();
316+
let hubris = &context.cli.try_archive()?;
317317

318-
let image_id = hubris.image_id();
318+
let image_id = hubris.as_ref().and_then(|h| h.image_id());
319319
if image_id.is_none() {
320320
humility::warn!("no archive provided; not checking for compatibility");
321321
}
@@ -330,6 +330,5 @@ pub fn init() -> Command {
330330
app: DiscoverArgs::command(),
331331
name: "discover",
332332
run: discover_run,
333-
kind: CommandKind::Detached { archive: Archive::Optional },
334333
}
335334
}

cmd/doc/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use anyhow::{Result, bail};
1414
use clap::{CommandFactory, Parser};
1515
use humility_cli::ExecutionContext;
16-
use humility_cmd::{Archive, Command, CommandKind};
16+
use humility_cmd::Command;
1717
use std::collections::HashMap;
1818
use termimad::*;
1919

@@ -64,10 +64,5 @@ fn doc(context: &mut ExecutionContext) -> Result<()> {
6464
}
6565

6666
pub fn init() -> Command {
67-
Command {
68-
app: DocArgs::command(),
69-
name: "doc",
70-
run: doc,
71-
kind: CommandKind::Unattached { archive: Archive::Ignored },
72-
}
67+
Command { app: DocArgs::command(), name: "doc", run: doc }
7368
}

0 commit comments

Comments
 (0)