1use crate::types::Config;
2use clap::{Args, Parser};
3use std::num::NonZeroUsize;
4use std::path::PathBuf;
5
6#[derive(Debug, Parser)]
7#[command(
8 name = "cargo-ff",
9 bin_name = "cargo ff",
10 about = "Fast Format is a fast drop-in replacement for cargo fmt",
11 version
12)]
13pub struct Cli {
14 #[arg(long)]
16 pub check: bool,
17
18 #[arg(long)]
22 pub all: bool,
23
24 #[arg(short = 'p', long = "package")]
26 pub packages: Vec<String>,
27
28 #[arg(long)]
30 pub manifest_path: Option<PathBuf>,
31
32 #[arg(last = true)]
34 pub rustfmt_args: Vec<String>,
35
36 #[command(flatten)]
37 pub ff: FfArgs,
38}
39
40#[derive(Debug, Args)]
43pub struct FfArgs {
44 #[arg(long = "ff-workers")]
46 pub workers: Option<NonZeroUsize>,
47
48 #[arg(long = "ff-channel-capacity", hide = true)]
50 pub channel_capacity: Option<usize>,
51
52 #[arg(long = "ff-batch-size", hide = true)]
55 pub batch_size: Option<usize>,
56
57 #[arg(long = "ff-experimental-cache", hide = true)]
61 pub experimental_cache: bool,
62
63 #[arg(long = "ff-warnings")]
65 pub warnings: bool,
66}
67
68impl Cli {
69 pub fn parse_argv() -> Self {
71 let mut args: Vec<std::ffi::OsString> = std::env::args_os().collect();
72 if args.len() >= 2 && args[1] == "ff" {
73 args.remove(1);
74 }
75 Cli::parse_from(args)
76 }
77
78 pub fn into_config(self) -> Config {
79 Config {
80 manifest_path: self.manifest_path,
81 packages: self.packages,
82 all: self.all,
83 check: self.check,
84 rustfmt_args: self.rustfmt_args,
85 workers: self.ff.workers.map(NonZeroUsize::get),
86 channel_capacity: self.ff.channel_capacity,
87 batch_size: self.ff.batch_size,
88 experimental_cache: self.ff.experimental_cache,
89 warnings: self.ff.warnings,
90 }
91 }
92}