Skip to content

Commit 6c8be58

Browse files
committed
cleanup graph fns
1 parent 984e9b0 commit 6c8be58

File tree

1 file changed

+47
-38
lines changed

1 file changed

+47
-38
lines changed

src/rust-cli/graph.rs

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -202,51 +202,60 @@ fn validate_schema(graph: &PathBuf) -> anyhow::Result<()> {
202202
Ok(())
203203
}
204204

205-
pub async fn handle_graph_command(command: &GraphCommand) -> anyhow::Result<()> {
206-
match command {
207-
GraphCommand::Create {
208-
number,
209-
outfile,
210-
version,
211-
bitcoin_conf,
212-
} => {
213-
let version_str: &str = version.as_deref().unwrap_or("26.0");
205+
fn handle_create_command(
206+
number: &usize,
207+
outfile: &Option<PathBuf>,
208+
version: &Option<String>,
209+
bitcoin_conf: &Option<PathBuf>,
210+
) -> anyhow::Result<()> {
211+
let version_str: &str = version.as_deref().unwrap_or("26.0");
214212

215-
// Create empty graph
216-
let graph: DiGraph<(), ()> = create_graph(*number).context("creating graph")?;
213+
// Create empty graph
214+
let graph: DiGraph<(), ()> = create_graph(*number).context("creating graph")?;
217215

218-
// Parse any custom bitcoin conf
219-
let bitcoin_conf: String = handle_bitcoin_conf(bitcoin_conf.as_deref());
216+
// Parse any custom bitcoin conf
217+
let bitcoin_conf: String = handle_bitcoin_conf(bitcoin_conf.as_deref());
220218

221-
// Dump graph to graphml format
222-
let graphml_buf: Vec<u8> = convert_to_graphml(&graph).context("Convert to graphml")?;
219+
// Dump graph to graphml format
220+
let graphml_buf: Vec<u8> = convert_to_graphml(&graph).context("Convert to graphml")?;
223221

224-
// Configure graphml output settings
225-
let graphml_config = EmitterConfig {
226-
write_document_declaration: true,
227-
perform_indent: true,
228-
indent_string: Cow::Borrowed(" "),
229-
line_separator: Cow::Borrowed("\n"),
230-
..Default::default() // Keep other defaults
231-
};
222+
// Configure graphml output settings
223+
let graphml_config = EmitterConfig {
224+
write_document_declaration: true,
225+
perform_indent: true,
226+
indent_string: Cow::Borrowed(" "),
227+
line_separator: Cow::Borrowed("\n"),
228+
..Default::default() // Keep other defaults
229+
};
232230

233-
// Add custom elements to graph
234-
let modified_graphml: xmltree::Element =
235-
add_custom_attributes(graphml_buf, version_str, bitcoin_conf.as_str());
231+
// Add custom elements to graph
232+
let modified_graphml: xmltree::Element =
233+
add_custom_attributes(graphml_buf, version_str, bitcoin_conf.as_str());
236234

237-
// Write either to outfile or stdout
238-
match outfile {
239-
Some(path) => {
240-
let file = File::create(path).context("Writing final graphml file")?;
241-
modified_graphml.write_with_config(file, graphml_config)?;
242-
}
243-
None => {
244-
let stdout = std::io::stdout();
245-
let handle = stdout.lock();
246-
modified_graphml.write_with_config(handle, graphml_config)?;
247-
}
248-
}
235+
// Write either to outfile or stdout
236+
match outfile {
237+
Some(path) => {
238+
let file = File::create(path).context("Writing final graphml file")?;
239+
modified_graphml.write_with_config(file, graphml_config)?;
240+
}
241+
None => {
242+
let stdout = std::io::stdout();
243+
let handle = stdout.lock();
244+
modified_graphml.write_with_config(handle, graphml_config)?;
249245
}
246+
}
247+
Ok(())
248+
}
249+
250+
pub async fn handle_graph_command(command: &GraphCommand) -> anyhow::Result<()> {
251+
match command {
252+
GraphCommand::Create {
253+
number,
254+
outfile,
255+
version,
256+
bitcoin_conf,
257+
} => handle_create_command(number, outfile, version, bitcoin_conf)
258+
.context("Create a graph")?,
250259

251260
GraphCommand::Validate { graph } => {
252261
let _ = validate_schema(graph);

0 commit comments

Comments
 (0)