Skip to content

Construct ExecutionContext in humility-bin#677

Open
mkeeter wants to merge 1 commit into
masterfrom
mkeeter/context-building
Open

Construct ExecutionContext in humility-bin#677
mkeeter wants to merge 1 commit into
masterfrom
mkeeter/context-building

Conversation

@mkeeter
Copy link
Copy Markdown
Contributor

@mkeeter mkeeter commented May 21, 2026

(staged on #666)

ExecutionContext::new is a weird function: it usually builds an ExecutionContext, but sometimes bails out unceremoniously with std::process::exit. This is because it's also handling a final set of subcommands-as-cli-flags, e.g. --list-targets.

In this PR, we move all of that logic into humility-bin, which is already designed to exit with a std::process::ExitCode (instead of calling exit(..) directly).

Logic should be the same, but this moves --list-targets handling earlier (which should fix #597).

@mkeeter mkeeter requested review from hawkw and jamesmunns May 21, 2026 20:41
@mkeeter mkeeter force-pushed the mkeeter/context-building branch from b85f4b5 to 92ebd5d Compare May 21, 2026 20:50
@mkeeter mkeeter force-pushed the mkeeter/subcommand-enum branch from f49aa94 to 20d913b Compare May 21, 2026 20:50
Copy link
Copy Markdown

@jamesmunns jamesmunns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of pedantic nits, feel free to take them or leave them :)

Comment thread humility-bin/src/main.rs
if let Ok(e) = env::var("HUMILITY_PROBE") {
cli.probe = Some(e);
} else if let Ok(e) = env::var("HUMILITY_IP") {
cli.ip = Some(e.parse().unwrap_or_else(|x| match x {}));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait how is parse returning Infallible here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over in #668, we made IP parsing lazier – the parse captures a Result<..> which is only checked if we're actually using the IP address.

Comment thread humility-bin/src/main.rs
// dump. If the user has specified no command line options but
// multiple of these in the environment, they will get the first in
// this ordering that we find.
if cli.dump.is_none()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a note, but it's probably not worth fixating on because this isn't new code:

It feels like there should be a nicer way to specify this, or at least, the semantics of what we've chosen as "the acceptable set of configuration combinations" feels overly complicated. Especially the repeated "is_some", matches, and asserts. I feel like I need a flowchart to follow this now :D

I have no calibration for "necessary complexity" vs "incidental complexity" here, but just leaving a note as an uninformed newcomer that "whew, this feels like a lot". It might be worth having a couple of functions for each acceptable source/combo of options to make it easier to hang documentation off of, so folks know what is/isn't allowed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the rework RFD, i would like to get rid of environments and just have other tooling set HUMILITY_PROBE and HUMILITY_ARCHIVE as appropriate. Environments solved an actual problem for us but I do not think the belong in a humility binary.

Comment thread humility-bin/src/main.rs
// Cannot specify a dump/probe/IP address and also an
// environment and target
//
assert!(cli.dump.is_none());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe turn these asserts into ExitCode::FAILUREs too, to be polite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutual exclusion between these options is enforced by clap; I'll add a comment.

Comment thread humility-bin/src/main.rs Outdated
PROBES_ENABLED
);
if cmd.is_some() {
humility::warn!("ignoring subcommand after printing version");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in scope

Suggested change
humility::warn!("ignoring subcommand after printing version");
warn!("ignoring subcommand after printing version");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it wasn't in scope in the previous file that I copied from

Comment thread humility-bin/src/main.rs Outdated
// The --version (-V) and --list-targets operations are implemented as
// flags, rather than subcommands, so we'll special-case them here.
if cli.version {
eprintln!(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we use humility::warn!, humility::msg!, and eprintln!?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, it's purely based on vibes! We'll want to standardize on log, but that's further down the line.

Comment thread humility-bin/src/main.rs Outdated
Comment thread humility-bin/src/main.rs Outdated
@mkeeter mkeeter force-pushed the mkeeter/context-building branch 4 times, most recently from 3a25b11 to bbb641c Compare May 26, 2026 14:20
@mkeeter mkeeter force-pushed the mkeeter/subcommand-enum branch 2 times, most recently from 52f87ad to fa8ee6b Compare May 27, 2026 17:18
@mkeeter mkeeter force-pushed the mkeeter/context-building branch from bbb641c to c1ffe04 Compare May 27, 2026 17:18
Copy link
Copy Markdown
Contributor

@labbott labbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of me really wants to have a separate binary for dealing with humility dumps simply so the logic here isn't so complicated. I have convinced myself this is fine but it should probably be spot checked against our lab machines for good measure.

Comment thread humility-bin/src/main.rs
// dump. If the user has specified no command line options but
// multiple of these in the environment, they will get the first in
// this ordering that we find.
if cli.dump.is_none()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in the rework RFD, i would like to get rid of environments and just have other tooling set HUMILITY_PROBE and HUMILITY_ARCHIVE as appropriate. Environments solved an actual problem for us but I do not think the belong in a humility binary.

@mkeeter mkeeter force-pushed the mkeeter/context-building branch from c1ffe04 to 17f9a92 Compare May 27, 2026 19:30
@mkeeter mkeeter force-pushed the mkeeter/subcommand-enum branch from fa8ee6b to 2b6fcbb Compare May 27, 2026 19:30
@mkeeter mkeeter force-pushed the mkeeter/context-building branch 2 times, most recently from a32ff10 to 840972b Compare May 27, 2026 19:48
Base automatically changed from mkeeter/subcommand-enum to master May 27, 2026 20:59
@mkeeter mkeeter force-pushed the mkeeter/context-building branch from 840972b to f1ce3d7 Compare May 27, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants