Skip to content

Commit 29f9ab5

Browse files
committed
feat: add --no-banner
1 parent 5cfff12 commit 29f9ab5

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

cbundl.toml

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
output = "test/frob/final.c"
33
deterministic = false
44

5+
[banner]
6+
enable = true
7+
58
[formatter]
69
# enable = true
710
# path = "clang-format"

src/cli.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub fn run() -> Result<()> {
2121

2222
let mut pipeline = Pipeline {
2323
bundler: Bundler {},
24-
banner: Banner {
24+
banner: (!config.no_banner).then_some(Banner {
2525
quotes: Quotes {},
2626
deterministic: config.deterministic,
27-
},
27+
}),
2828
formatter: (!config.no_format).then_some(Formatter {
2929
exe: config.formatter,
3030
}),

src/config.rs

+63-37
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ struct Args {
3434
)]
3535
config: Option<PathBuf>,
3636

37-
#[arg(long, help = "Don't pass the resulting bundle through the formatter.")]
38-
no_format: bool,
39-
40-
#[arg(
41-
long,
42-
help = "Code formatter executable.",
43-
long_help = "Code formatter. Must format the code from stdin and write it to stdout.",
44-
value_name = "exe",
45-
default_value = DEFAULT_FORMATTER
46-
)]
47-
formatter: PathBuf,
48-
4937
#[arg(long = "deterministic", help = "Output a deterministic bundle.")]
5038
deterministic: bool,
5139

@@ -58,13 +46,29 @@ struct Args {
5846
)]
5947
output_file: PathBuf,
6048

49+
#[arg(long, help = "Don't output the banner at the top of the bundle.")]
50+
no_banner: bool,
51+
52+
#[arg(long, help = "Don't pass the resulting bundle through the formatter.")]
53+
no_format: bool,
54+
55+
#[arg(
56+
long,
57+
help = "Code formatter executable.",
58+
long_help = "Code formatter. Must format the code from stdin and write it to stdout.",
59+
value_name = "exe",
60+
default_value = DEFAULT_FORMATTER
61+
)]
62+
formatter: PathBuf,
63+
6164
#[arg(help = "Path to the entry source file.", value_name = "path")]
6265
entry: PathBuf,
6366
}
6467

6568
#[derive(Debug, Clone, Deserialize)]
6669
struct File {
6770
bundle: Option<BundleSection>,
71+
banner: Option<BannerSection>,
6872
formatter: Option<FormatterSection>,
6973
}
7074

@@ -76,6 +80,11 @@ struct BundleSection {
7680
output_file: Option<PathBuf>,
7781
}
7882

83+
#[derive(Debug, Clone, Deserialize)]
84+
struct BannerSection {
85+
enable: Option<bool>,
86+
}
87+
7988
#[derive(Debug, Clone, Deserialize)]
8089
struct FormatterSection {
8190
enable: Option<bool>,
@@ -148,10 +157,14 @@ impl ArgMatchesExt for ArgMatches {
148157

149158
#[derive(Debug, Clone)]
150159
pub struct Config {
151-
pub no_format: bool,
152-
pub formatter: PathBuf,
153160
pub deterministic: bool,
154161
pub output_file: Option<PathBuf>,
162+
163+
pub no_banner: bool,
164+
165+
pub no_format: bool,
166+
pub formatter: PathBuf,
167+
155168
pub entry: PathBuf,
156169
}
157170

@@ -171,27 +184,6 @@ impl Config {
171184
File::read_many(DEFAULT_CONFIG_FILES.iter().copied().map(Path::new))
172185
};
173186

174-
let no_format = args
175-
.flag("no_format")
176-
.or_else(|| {
177-
file.as_ref()
178-
.and_then(|x| x.formatter.as_ref())
179-
.and_then(|x| x.enable)
180-
.map(|x| !x)
181-
})
182-
.unwrap_or(false);
183-
184-
let formatter = args
185-
.value::<PathBuf>("formatter")
186-
.cloned()
187-
.or_else(|| {
188-
file.as_ref()
189-
.and_then(|x| x.formatter.as_ref())
190-
.and_then(|x| x.path.as_ref())
191-
.cloned()
192-
})
193-
.unwrap_or_else(|| PathBuf::from(DEFAULT_FORMATTER));
194-
195187
let deterministic = args
196188
.flag("deterministic")
197189
.or_else(|| {
@@ -215,13 +207,47 @@ impl Config {
215207
})
216208
.unwrap_or(None);
217209

210+
let no_banner = args
211+
.flag("no_banner")
212+
.or_else(|| {
213+
file.as_ref()
214+
.and_then(|x| x.banner.as_ref())
215+
.and_then(|x| x.enable)
216+
})
217+
.unwrap_or(false);
218+
219+
let no_format = args
220+
.flag("no_format")
221+
.or_else(|| {
222+
file.as_ref()
223+
.and_then(|x| x.formatter.as_ref())
224+
.and_then(|x| x.enable)
225+
.map(|x| !x)
226+
})
227+
.unwrap_or(false);
228+
229+
let formatter = args
230+
.value::<PathBuf>("formatter")
231+
.cloned()
232+
.or_else(|| {
233+
file.as_ref()
234+
.and_then(|x| x.formatter.as_ref())
235+
.and_then(|x| x.path.as_ref())
236+
.cloned()
237+
})
238+
.unwrap_or_else(|| PathBuf::from(DEFAULT_FORMATTER));
239+
218240
let entry = args.value::<PathBuf>("entry").unwrap().clone();
219241

220242
Ok(Self {
221-
no_format,
222-
formatter,
223243
deterministic,
224244
output_file,
245+
246+
no_banner,
247+
248+
no_format,
249+
formatter,
250+
225251
entry,
226252
})
227253
}

src/pipeline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<S: Stage> Stage for Option<S> {
2626
#[derive(Debug, Clone)]
2727
pub struct Pipeline {
2828
pub bundler: Bundler,
29-
pub banner: Banner,
29+
pub banner: Option<Banner>,
3030
pub formatter: Option<Formatter>,
3131
}
3232

0 commit comments

Comments
 (0)