Skip to content

Commit c38dfd5

Browse files
committed
docs: update README and example config to include explanations
1 parent 330ff2e commit c38dfd5

File tree

2 files changed

+86
-6
lines changed

2 files changed

+86
-6
lines changed

README.md

+33-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ A simple tool that makes self-contained abominations of C code called bundles. I
3737
* [Directives](#directives)
3838
* [bundle](#bundle)
3939
* [impl](#impl)
40+
* [Configuration](#configuration)
4041
* [Workflow](#workflow)
4142
* [Installation](#installation)
4243
* [cargo](#cargo)
@@ -210,22 +211,39 @@ Arguments:
210211
Path to the entry source file.
211212

212213
Options:
213-
--no-format
214-
Don't pass the resulting bundle through the formatter.
214+
--no-config
215+
Don't load any configuration file. (Overrides `--config`)
215216

216-
--formatter <exe>
217-
Code formatter. Must format the code from stdin and write it to stdout.
217+
--config <path>
218+
Specify an alternate configuration file.
218219

219-
[default: clang-format]
220+
[default: .cbundl.toml cbundl.toml]
220221

221-
--deterministic
222+
--deterministic[=<boolean>]
222223
Output a deterministic bundle.
223224

225+
[possible values: yes, no]
226+
224227
-o, --output <path>
225228
Specify where to write the resulting bundle.
226229

227230
[default: -]
228231

232+
--no-banner[=<boolean>]
233+
Don't output the banner at the top of the bundle.
234+
235+
[possible values: yes, no]
236+
237+
--no-format[=<boolean>]
238+
Don't pass the resulting bundle through the formatter.
239+
240+
[possible values: yes, no]
241+
242+
--formatter <exe>
243+
Code formatter. Must format the code from stdin and write it to stdout.
244+
245+
[default: clang-format]
246+
229247
-h, --help
230248
Print help (see a summary with '-h')
231249

@@ -262,6 +280,15 @@ The bundle directive must always appear exactly above a local `#include`, withou
262280

263281
The `impl` directive, also called an implementation directive, informs `cbundl` that the current file is implemented by the file specified by `<path>`. This directive can appear any number of times in the file (if the implementation is split across many other files). It can also appear anywhere in the file, but convention is that `impl` directives appear only at either the start or the end of the file. Just like `#include`-ing `.c` files, using an implementation directive that points to a `.h` file is generally considered bad practice.
264282

283+
### Configuration
284+
285+
`cbundl` can be configured via a configuration file. The configuration file exposes fine-grained settings for `cbundl` not available through the command line. By default, `cbundl` looks for configuration files named `.cbundl.toml` or `cbundl.toml` (in that order), though a custom configuration file can be specified via `--config`. Alternatively, `--no-config` tells `cbundl` to ignore any configuration files.
286+
287+
> [!NOTE]
288+
> Command line flags always take priority over the configuration file.
289+
290+
Configuration files for `cbundl` are written in [TOML](https://toml.io/en). An example configuration is given in [`cbundl.toml`](./cbundl.toml).
291+
265292
### Workflow
266293

267294
Ok that's all cool and all but how do I integrate it into my workflow? I'm glad you asked. Simple, instead of running just:

cbundl.toml

+53
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,85 @@
11
[bundle]
2+
# Add separators between the contents of each source file inside the bundle.
23
separators = true
4+
5+
# Produce a deterministic bundle. This switch makes cbundl a pure function.
6+
# This means that for the same source files, the same bundle is always produced.
7+
# One sideffect is that dates will be displayed as the UNIX epoch and quotes
8+
# will always be the same. This switch is useful if you intend to check into
9+
# source control the bundle, where you wouldn't want to pollute diffs with
10+
# changed to the generated date, or the quotes inside the bundle.
311
deterministic = false
12+
13+
# Write the final bundle to this path.
414
output = "test/frob/final.c"
515

16+
##
17+
## This section configures a custom header to be added to the very top of the
18+
## bundle. Useful for adding license text or copyright notices.
19+
##
620
[header]
21+
# Whether to add the custom header.
722
enable = true
23+
24+
# The text to be added. Before you ask: yes, you can inject code from here but
25+
# you shouldn't have to. If you find yourself doing that, you are doing something
26+
# wrong.
827
text = """
928
// My amazing header text!
1029
"""
30+
31+
# Specify a file which contains the text for the header. The contents of the file
32+
# will be pasted in verbatim. This means that the file must contain the text in
33+
# C comments.
1134
#source = "header.txt"
1235

36+
# NOTE: `text` and `source` cannot be specified both at the same time.
37+
38+
##
39+
## This section configures the banner at the top of the bundle.
40+
##
1341
[banner]
42+
# Whether to add the banner.
1443
enable = true
1544

45+
##
46+
## This section configures the quotes displayed inside the banner.
47+
##
1648
[banner.quote]
49+
# Whether to add quotes inside the banner.
1750
enable = true
51+
52+
# Pick quotes from this location. Specifying "all" here will allow cbundl to
53+
# choose at random one quote without restrictions. "builtin" will only pick
54+
# quotes that are built-in to cbundl. "custom" will only pick quotes that are
55+
# configured here.
56+
#
57+
# Valid values: "all", "builtin", "custom"
1858
pick = "custom"
1959

60+
##
61+
## This section configures how cbundl will format the bundle.
62+
##
2063
[formatter]
64+
# Whether to format the bundle.
2165
enable = true
66+
67+
# Path to the formatter binary. Specifying just the executable will make cbundl
68+
# search in PATH for it.
2269
path = "clang-format"
70+
71+
# Extra arguments to pass to the formatter.
2372
args = ["--verbose", "--sort-includes"]
2473

74+
75+
# A custom quote.
2576
[[quote]]
77+
# Quote text. Will appear as is.
2678
text = """
2779
Use a gun. And if that don't work...
2880
use more gun.
2981
"""
82+
# Quote author. Make sure to give proper credit.
3083
author = "Dr. Dell Conagher"
3184

3285
[[quote]]

0 commit comments

Comments
 (0)