Skip to content

Construct ExecutionContext in humility-bin#677

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

Construct ExecutionContext in humility-bin#677
mkeeter wants to merge 1 commit into
mkeeter/subcommand-enumfrom
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.

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 2 times, most recently from 5a3540f to c9f203a Compare May 22, 2026 13:23
@mkeeter mkeeter force-pushed the mkeeter/context-building branch from c9f203a to 3a25b11 Compare May 22, 2026 13:47
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.

2 participants