Skip to content

feat(unpinned-images): Docker CLI models with clap - #1711

Open
jfagoagas wants to merge 1 commit into
zizmorcore:mainfrom
jfagoagas:docker-cli-models
Open

feat(unpinned-images): Docker CLI models with clap#1711
jfagoagas wants to merge 1 commit into
zizmorcore:mainfrom
jfagoagas:docker-cli-models

Conversation

@jfagoagas

Copy link
Copy Markdown

Pre-submission checks

Please check these boxes:

  • Mandatory: This PR corresponds to an issue (if not, please create
    one first).

  • I hereby disclose the use of an LLM or other AI coding assistant in the
    creation of this PR. PRs will not be rejected for using AI tools, but
    will be rejected for undisclosed use.

If a checkbox is not applicable, you can leave it unchecked.

Summary

  • Add clap-derive structs modeling Docker's CLI for pull, run, and create subcommands
  • Single public API: DockerCli::parse_image(args: &[&str]) -> Option<String>
  • Replaces the hand-rolled flag parsing approach with clap's built-in handling of combined short flags (-dit), --flag=value syntax, and embedded values (-eFOO=bar)
  • The -a flag ambiguity (boolean --all-tags in pull vs value-consuming --attach in run/create) is resolved per-subcommand automatically
  • Unknown subcommands or parse failures return None (safe false negatives)
  • Docker-only flags; Podman support comes in a follow-up PR

Part 1 of a PR chain splitting #1677 into reviewable pieces:

  1. This PR: Docker CLI models with clap
  2. Audit integration (delete hand-rolled parsing, wire up DockerCli::parse_image)
  3. Podman CLI model
  4. Documentation

Test plan

  • 22 unit tests covering subcommand routing, combined flags, value-consuming flags, --flag=value, -a ambiguity, global flags, trailing
    commands, and edge cases
  • cargo clippy -p zizmor clean (only expected dead_code warning since PR 2 is the consumer)

Copilot AI review requested due to automatic review settings March 6, 2026 20:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Introduces a clap-based Docker CLI argument model to extract image references from docker pull, docker run, and docker create invocations (intended for upcoming unpinned-images audit enhancements).

Changes:

  • Added models/docker.rs with clap Parser/Args/Subcommand structs and DockerCli::parse_image(args) -> Option<String>.
  • Added unit tests covering subcommand routing and common flag syntaxes/edge cases.
  • Wired the new module into crates/zizmor/src/models.rs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/zizmor/src/models/docker.rs Adds clap-based Docker CLI parsing model + tests for image extraction.
crates/zizmor/src/models.rs Registers the new docker models module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +30
#[derive(Parser, Debug)]
#[command(
no_binary_name = true,
disable_help_flag = true,
disable_version_flag = true
)]
struct DockerCli {
#[command(flatten)]
_global: DockerGlobalFlags,

#[command(subcommand)]
command: DockerCommand,
}

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

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

DockerCli::parse_image is pub(crate), but the DockerCli type itself is private (struct DockerCli). That makes the advertised API unusable from other modules (you can't name DockerCli outside this module), which will block the follow-up PR that consumes it. Make DockerCli pub(crate) (or expose a pub(crate) free function) so callers can access the parser without re-export hacks.

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +43
// Boolean global flags
#[arg(short = 'D', long = "debug")]
_debug: bool,

#[arg(long = "tls")]
_tls: bool,

#[arg(long = "tlsverify")]
_tlsverify: bool,

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

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

Docker (via Go pflag) typically allows boolean flags to be specified with an explicit value (e.g. --debug=false, --tlsverify=true). Modeling these as plain bool flags in clap will reject --flag=false / --flag=true, causing try_parse_from to fail and parse_image to return None (missed detections). Consider switching boolean options to accept an optional bool value (e.g. action=Set, num_args=0..=1, default_missing_value="true", with a boolish value parser) so both --flag and --flag=false parse successfully.

Copilot uses AI. Check for mistakes.
@jfagoagas

Copy link
Copy Markdown
Author

Hi @woodruffw any update on this? Thanks!

@woodruffw

Copy link
Copy Markdown
Member

Sorry, I've been traveling and haven't had a lot of time to look at my review backlog. With some luck, I'll have time to look at this next week.

@jfagoagas

Copy link
Copy Markdown
Author

Sorry, I've been traveling and haven't had a lot of time to look at my review backlog. With some luck, I'll have time to look at this next week.

Hey @woodruffw any updates?

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