diff --git a/crates/pollard-cli/src/main.rs b/crates/pollard-cli/src/main.rs index 719ca837..699be9fb 100644 --- a/crates/pollard-cli/src/main.rs +++ b/crates/pollard-cli/src/main.rs @@ -44,25 +44,25 @@ enum StepAction { FindFiles, DeriveMutants, CreateWorkspaces, - ApplyMutantToWorkspace { + SetupWorkspace { #[arg(short, long)] workspace: String, - #[arg(long)] - mutant: Hash, }, - SetupWorkspace { + ResetWorkspace { #[arg(short, long)] workspace: String, + #[arg(short, long)] + rev: String, }, - TestWorkspace { + ApplyMutantToWorkspace { #[arg(short, long)] workspace: String, + #[arg(long)] + mutant: Hash, }, - ResetWorkspace { + TestWorkspace { #[arg(short, long)] workspace: String, - #[arg(short, long)] - rev: String, }, Cleanup, } @@ -146,7 +146,12 @@ fn main() { let cli = Cli::parse(); if let Command::Completions { shell } = &cli.command { - clap_complete::generate(*shell, &mut Cli::command(), "pollard", &mut std::io::stdout()); + clap_complete::generate( + *shell, + &mut Cli::command(), + "pollard", + &mut std::io::stdout(), + ); return; } diff --git a/crates/pollard-cli/src/mutate/apply.rs b/crates/pollard-cli/src/mutate/apply.rs index 85b86460..3cc9c5ea 100644 --- a/crates/pollard-cli/src/mutate/apply.rs +++ b/crates/pollard-cli/src/mutate/apply.rs @@ -62,7 +62,7 @@ impl Report for ApplyReport { } Style::Pretty => { println!( - "Applied mutation {} to {}", + "Will apply mutation {} to {}", color("\x1b[33m", &self.mutated_hash.to_string(), no_color), color( "\x1b[36m", @@ -73,7 +73,7 @@ impl Report for ApplyReport { } Style::Plain | Style::Markdown => { println!( - "Applied mutation {} to {}", + "Will apply mutation {} to {}", self.mutated_hash, self.source_path.display(), ); diff --git a/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs b/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs index 8b6f517c..9654e7b3 100644 --- a/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs +++ b/crates/pollard-cli/src/steps/apply_mutant_to_workspace.rs @@ -89,7 +89,7 @@ impl Report for ApplyMutantToWorkspaceReport { } Style::Pretty => { println!( - "Applied mutation {} to {}", + "Will apply mutation {} to {}", color("\x1b[33m", &self.mutated_hash.to_string(), no_color), color( "\x1b[36m", @@ -100,7 +100,7 @@ impl Report for ApplyMutantToWorkspaceReport { } Style::Plain | Style::Markdown => { println!( - "Applied mutation {} to {}", + "Will apply mutation {} to {}", self.mutated_hash, self.source_path.display(), ); diff --git a/crates/pollard-cli/src/steps/cleanup.rs b/crates/pollard-cli/src/steps/cleanup.rs index 00778850..5309d5f9 100644 --- a/crates/pollard-cli/src/steps/cleanup.rs +++ b/crates/pollard-cli/src/steps/cleanup.rs @@ -71,14 +71,14 @@ impl Report for CleanupReport { } Style::Pretty => { println!( - "Cleaned up {} workspaces from {} manifests", + "Will clean up {} workspaces from {} manifests", color("\x1b[33m", &self.workspace_count.to_string(), no_color), color("\x1b[36m", &self.manifest_count.to_string(), no_color), ); } Style::Plain | Style::Markdown => { println!( - "Cleaned up {} workspaces from {} manifests", + "Will clean up {} workspaces from {} manifests", self.workspace_count, self.manifest_count, ); } diff --git a/crates/pollard-cli/src/steps/create_workspaces.rs b/crates/pollard-cli/src/steps/create_workspaces.rs index ea5e5cc7..f932e4e0 100644 --- a/crates/pollard-cli/src/steps/create_workspaces.rs +++ b/crates/pollard-cli/src/steps/create_workspaces.rs @@ -83,7 +83,7 @@ impl Report for CreateWorkspacesReport { } Style::Pretty => { println!( - "Created {} workspaces, manifest: {}", + "Will create {} workspaces, manifest: {}", color("\x1b[33m", &self.workspaces.len().to_string(), no_color), color("\x1b[36m", &self.manifest.display().to_string(), no_color), ); @@ -93,7 +93,7 @@ impl Report for CreateWorkspacesReport { } Style::Plain | Style::Markdown => { println!( - "Created {} workspaces, manifest: {}", + "Will create {} workspaces, manifest: {}", self.workspaces.len(), self.manifest.display() ); diff --git a/crates/pollard-cli/src/steps/derive_mutants.rs b/crates/pollard-cli/src/steps/derive_mutants.rs index 14b9ccb9..e1f13b6b 100644 --- a/crates/pollard-cli/src/steps/derive_mutants.rs +++ b/crates/pollard-cli/src/steps/derive_mutants.rs @@ -97,14 +97,14 @@ impl Report for DeriveMutantsReport { } Style::Pretty => { println!( - "Derived {} mutations, wrote to {}", + "Derived {} mutations, will write to {}", color("\x1b[33m", &self.count.to_string(), no_color), color("\x1b[36m", &self.path.display().to_string(), no_color), ); } Style::Plain | Style::Markdown => { println!( - "Derived {} mutations, wrote to {}", + "Derived {} mutations, will write to {}", self.count, self.path.display() ); diff --git a/crates/pollard-cli/src/steps/find_files.rs b/crates/pollard-cli/src/steps/find_files.rs index 3bc0594c..c9323d15 100644 --- a/crates/pollard-cli/src/steps/find_files.rs +++ b/crates/pollard-cli/src/steps/find_files.rs @@ -41,7 +41,7 @@ impl Report for FindFilesReport { } Style::Pretty => { println!( - "Found {} files matching {}", + "{} files match {}", crate::steps::color("\x1b[33m", &self.files.len().to_string(), no_color), crate::steps::color("\x1b[36m", &self.pattern, no_color), ); @@ -50,7 +50,7 @@ impl Report for FindFilesReport { } } Style::Plain | Style::Markdown => { - println!("Found {} files matching {}", self.files.len(), self.pattern); + println!("{} files match {}", self.files.len(), self.pattern); for f in &self.files { println!(" {}", f.display()); } diff --git a/crates/pollard-cli/src/steps/reset_workspace.rs b/crates/pollard-cli/src/steps/reset_workspace.rs index fdc05186..5875ce77 100644 --- a/crates/pollard-cli/src/steps/reset_workspace.rs +++ b/crates/pollard-cli/src/steps/reset_workspace.rs @@ -70,13 +70,13 @@ impl Report for ResetWorkspaceReport { } Style::Pretty => { println!( - "Reset {} to {}", + "Will reset {} to {}", color("\x1b[33m", &self.workspace, no_color), color("\x1b[36m", &self.rev, no_color), ); } Style::Plain | Style::Markdown => { - println!("Reset {} to {}", self.workspace, self.rev); + println!("Will reset {} to {}", self.workspace, self.rev); } } } diff --git a/crates/pollard-session-derive/src/settings.rs b/crates/pollard-session-derive/src/settings.rs index d832fb6b..cb854c84 100644 --- a/crates/pollard-session-derive/src/settings.rs +++ b/crates/pollard-session-derive/src/settings.rs @@ -10,6 +10,7 @@ struct FieldInfo { ty: Type, is_option: bool, is_vec: bool, + is_bool: bool, skip: bool, cli_only: bool, flatten: bool, @@ -32,6 +33,15 @@ fn extract_inner_type(ty: &Type) -> Option<&Type> { None } +fn is_bare_type(ty: &Type, name: &str) -> bool { + if let Type::Path(type_path) = ty { + if let Some(seg) = type_path.path.segments.last() { + return seg.ident == name && seg.arguments.is_none(); + } + } + false +} + fn is_type_wrapper(ty: &Type, name: &str) -> bool { if let Type::Path(type_path) = ty { if let Some(seg) = type_path.path.segments.last() { @@ -46,6 +56,7 @@ fn parse_field(field: &Field) -> syn::Result { let ty = field.ty.clone(); let is_option = is_type_wrapper(&ty, "Option"); let is_vec = is_type_wrapper(&ty, "Vec"); + let is_bool = is_bare_type(&ty, "bool"); let mut skip = false; let mut cli_only = false; @@ -94,6 +105,7 @@ fn parse_field(field: &Field) -> syn::Result { ty, is_option, is_vec, + is_bool, skip, cli_only, flatten, @@ -187,6 +199,19 @@ fn gen_partial_fields(fields: &[FieldInfo]) -> Vec { #serde_skip pub #ident: Vec<#inner>, } + } else if f.is_bool { + let serde_skip = if f.cli_only { + quote! { #[serde(skip)] } + } else { + quote! { #[serde(default)] } + }; + let env_attr = f.env.as_ref().map(|e| quote! { env = #e, }); + let hide_env = f.env.as_ref().map(|_| quote! { hide_env = true, }); + quote! { + #[arg(long = #long_name, global = true, action = clap::ArgAction::SetTrue, #env_attr #hide_env)] + #serde_skip + pub #ident: bool, + } } else { let ty = if f.is_option { let inner = extract_inner_type(&f.ty).unwrap(); @@ -231,6 +256,8 @@ fn gen_merge_fields(fields: &[FieldInfo]) -> Vec { self.#ident }, } + } else if f.is_bool { + quote! { #ident: self.#ident || fallback.#ident, } } else { quote! { #ident: self.#ident.or(fallback.#ident), } } @@ -245,7 +272,7 @@ fn gen_resolve_fields(fields: &[FieldInfo], struct_name: &syn::Ident) -> TokenSt // Phase 1: check required fields, collect missing let check_stmts: Vec = fields .iter() - .filter(|f| !f.skip && !f.flatten && !f.is_vec && !f.is_option && f.default_expr.is_none()) + .filter(|f| !f.skip && !f.flatten && !f.is_vec && !f.is_option && !f.is_bool && f.default_expr.is_none()) .map(|f| { let field_name = f.ident.to_string(); let ident = &f.ident; @@ -275,6 +302,10 @@ fn gen_resolve_fields(fields: &[FieldInfo], struct_name: &syn::Ident) -> TokenSt return quote! { #ident: self.#ident.resolve_no_skip()?, }; } + if f.is_bool { + return quote! { #ident: self.#ident, }; + } + if f.is_vec { return quote! { #ident: self.#ident, }; } diff --git a/crates/pollard-session/src/lib.rs b/crates/pollard-session/src/lib.rs index ccb0b415..1715ccbc 100644 --- a/crates/pollard-session/src/lib.rs +++ b/crates/pollard-session/src/lib.rs @@ -80,9 +80,9 @@ pub struct Session { pub style: Style, #[setting(default = "DiffStyle::Unified")] pub diff: DiffStyle, - #[setting(env = "NO_COLOR", default = "false")] + #[setting(env = "NO_COLOR")] pub no_color: bool, - #[setting(cli_only, default = "false")] + #[setting(cli_only)] pub exec: bool, #[setting(skip)] pub config_path: PathBuf,