Skip to content

Commit

Permalink
Omit and from annotation header unless requested
Browse files Browse the repository at this point in the history
  • Loading branch information
yasufumy committed Feb 23, 2024
1 parent b8b917a commit 06273e7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
33 changes: 31 additions & 2 deletions crates/uv/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub(crate) async fn pip_compile(
include_header: bool,
include_index_url: bool,
include_find_links: bool,
include_upgrade: bool,
include_quiet: bool,
index_locations: IndexLocations,
setup_py: SetupPyStrategy,
config_settings: ConfigSettings,
Expand Down Expand Up @@ -346,7 +348,16 @@ pub(crate) async fn pip_compile(
writeln!(
writer,
"{}",
format!("# {}", cmd(include_index_url, include_find_links)).green()
format!(
"# {}",
cmd(
include_index_url,
include_find_links,
include_upgrade,
include_quiet
)
)
.green()
)?;
}

Expand Down Expand Up @@ -393,7 +404,13 @@ pub(crate) async fn pip_compile(
}

/// Format the `uv` command used to generate the output file.
fn cmd(include_index_url: bool, include_find_links: bool) -> String {
#[allow(clippy::fn_params_excessive_bools)]
fn cmd(
include_index_url: bool,
include_find_links: bool,
include_upgrade: bool,
include_quiet: bool,
) -> String {
let args = env::args_os()
.skip(1)
.map(|arg| arg.normalized_display().to_string())
Expand Down Expand Up @@ -434,6 +451,18 @@ fn cmd(include_index_url: bool, include_find_links: bool) -> String {
}
}

// Skip --upgrade/-U flag
if !include_upgrade && (arg == "--upgrade" || arg == "-U") {
*skip_next = None;
return Some(None);
}

// Skip --quiet/-q flag
if !include_quiet && (arg == "--quiet" || arg == "-q") {
*skip_next = None;
return Some(None);
}

// Return the argument.
Some(Some(arg))
})
Expand Down
10 changes: 10 additions & 0 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ struct PipCompileArgs {
#[clap(long, hide = true)]
emit_find_links: bool,

/// Include `--upgrade` or `-U` entries in the generated output file.
#[clap(long, hide = true)]
emit_upgrade: bool,

/// Include `--quiet` or `-q` entries in the generated output file.
#[clap(long, hide = true)]
emit_quiet: bool,

/// Choose the style of the annotation comments, which indicate the source of each package.
#[clap(long, default_value_t=AnnotationStyle::Split, value_enum)]
annotation_style: AnnotationStyle,
Expand Down Expand Up @@ -908,6 +916,8 @@ async fn run() -> Result<ExitStatus> {
!args.no_header,
args.emit_index_url,
args.emit_find_links,
args.emit_upgrade,
args.emit_quiet,
index_urls,
setup_py,
config_settings,
Expand Down

0 comments on commit 06273e7

Please sign in to comment.