1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// ---------------- [ File: workspacer-cli/src/write.rs ]
crate::ix!();
/// A single fused enum with subcommands, each having **all** the config flags duplicated.
#[derive(StructOpt, Clone, Debug)]
pub enum ReadmeWriterCli {
/// Generate or update README for a single crate
SingleCrate {
/// If set, do not include doc comments in the crate interface.
#[structopt(long = "skip-docs")]
skip_docs: bool,
/// If set, do not include function bodies in the crate interface.
#[structopt(long = "skip-fn-bodies")]
skip_fn_bodies: bool,
/// If set, include test items (`#[cfg(test)]`) in the crate interface.
#[structopt(long = "include-test-items")]
include_test_items: bool,
/// If set, include private (non-pub) items in the crate interface.
#[structopt(long = "include-private-items")]
include_private_items: bool,
/// If set, the crate interface text is truncated if it exceeds this length.
#[structopt(long = "max-interface-length")]
max_interface_length: Option<usize>,
/// Path to the crate directory containing Cargo.toml
#[structopt(parse(from_os_str), long = "crate-path")]
crate_path: PathBuf,
/// If true, we write seeds (plant) but do not attempt to read expansions.
#[structopt(long = "plant")]
plant: bool,
/// Pass this to force re-writing an existing README
#[structopt(long = "force")]
force: bool,
},
/// Generate or update READMEs for multiple distinct crates
MultiCrate {
/// If set, do not include doc comments in the crate interface.
#[structopt(long = "skip-docs")]
skip_docs: bool,
/// If set, do not include function bodies in the crate interface.
#[structopt(long = "skip-fn-bodies")]
skip_fn_bodies: bool,
/// If set, include test items (`#[cfg(test)]`) in the crate interface.
#[structopt(long = "include-test-items")]
include_test_items: bool,
/// If set, include private (non-pub) items in the crate interface.
#[structopt(long = "include-private-items")]
include_private_items: bool,
/// If set, the crate interface text is truncated if it exceeds this length.
#[structopt(long = "max-interface-length")]
max_interface_length: Option<usize>,
/// Paths to the crate directories containing Cargo.toml
#[structopt(parse(from_os_str))]
crate_paths: Vec<PathBuf>,
/// If true, we write seeds (plant) but do not attempt to read expansions.
#[structopt(long = "plant")]
plant: bool,
/// Pass this to force re-writing an existing README
#[structopt(long = "force")]
force: bool,
},
/// Generate or update READMEs for an entire workspace
Workspace {
/// If set, do not include doc comments in the crate interface.
#[structopt(long = "skip-docs")]
skip_docs: bool,
/// If set, do not include function bodies in the crate interface.
#[structopt(long = "skip-fn-bodies")]
skip_fn_bodies: bool,
/// If set, include test items (`#[cfg(test)]`) in the crate interface.
#[structopt(long = "include-test-items")]
include_test_items: bool,
/// If set, include private (non-pub) items in the crate interface.
#[structopt(long = "include-private-items")]
include_private_items: bool,
/// If set, the crate interface text is truncated if it exceeds this length.
#[structopt(long = "max-interface-length")]
max_interface_length: Option<usize>,
/// Path to the workspace directory containing Cargo.toml(s)
#[structopt(parse(from_os_str), long = "workspace-path")]
workspace_path: PathBuf,
/// If true, we write seeds (plant) but do not attempt to read expansions.
#[structopt(long = "plant")]
plant: bool,
/// Pass this to force re-writing existing READMEs in the workspace
#[structopt(long = "force")]
force: bool,
},
}
impl ReadmeWriterCli {
/// Runs the readme-writer logic for whichever subcommand was chosen.
pub async fn run(&self) -> Result<(), WorkspaceError> {
match self {
Self::SingleCrate {
skip_docs,
skip_fn_bodies,
include_test_items,
include_private_items,
max_interface_length,
crate_path,
plant,
force,
} => {
// Build config from these fields:
let config = ReadmeWriterConfigBuilder::default()
.skip_docs(*skip_docs)
.skip_fn_bodies(*skip_fn_bodies)
.include_test_items(*include_test_items)
.include_private_items(*include_private_items)
.max_interface_length(*max_interface_length)
.build()
.unwrap();
trace!(
"SingleCrate => path={:?}, plant={}, force={}, config={:?}",
crate_path, plant, force, config
);
let handle = Arc::new(AsyncMutex::new(
CrateHandle::new(crate_path).await?
));
UpdateReadmeFiles::update_readme_files(handle, *plant, *force, &config).await?;
info!("Done updating readme for single crate at {:?}", crate_path);
}
Self::MultiCrate {
skip_docs,
skip_fn_bodies,
include_test_items,
include_private_items,
max_interface_length,
crate_paths,
plant,
force,
} => {
let config = ReadmeWriterConfigBuilder::default()
.skip_docs(*skip_docs)
.skip_fn_bodies(*skip_fn_bodies)
.include_test_items(*include_test_items)
.include_private_items(*include_private_items)
.max_interface_length(*max_interface_length)
.build()
.unwrap();
trace!(
"MultiCrate => paths={:?}, plant={}, force={}, config={:?}",
crate_paths, plant, force, config
);
for path in crate_paths {
let handle = Arc::new(AsyncMutex::new(
CrateHandle::new(path).await?
));
UpdateReadmeFiles::update_readme_files(handle, *plant, *force, &config).await?;
debug!("Finished readme updates for crate at {:?}", path);
}
info!("Done updating readmes for all crates in MultiCrate mode.");
}
Self::Workspace {
skip_docs,
skip_fn_bodies,
include_test_items,
include_private_items,
max_interface_length,
workspace_path,
plant,
force,
} => {
let config = ReadmeWriterConfigBuilder::default()
.skip_docs(*skip_docs)
.skip_fn_bodies(*skip_fn_bodies)
.include_test_items(*include_test_items)
.include_private_items(*include_private_items)
.max_interface_length(*max_interface_length)
.build()
.unwrap();
trace!(
"Workspace => path={:?}, plant={}, force={}, config={:?}",
workspace_path, plant, force, config
);
let ws = Arc::new(AsyncMutex::new(
Workspace::<PathBuf, CrateHandle>::new(workspace_path).await?
));
UpdateReadmeFiles::update_readme_files(ws, *plant, *force, &config).await?;
info!("Done updating readmes for entire workspace at {:?}", workspace_path);
}
}
info!("All done with readme-writer-cli. Exiting successfully.");
Ok(())
}
}