summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/butck.rs8
-rw-r--r--src/bin/butckrepo-guide.rs13
-rw-r--r--src/bin/butckrepo-refresh.rs32
3 files changed, 29 insertions, 24 deletions
diff --git a/src/bin/butck.rs b/src/bin/butck.rs
index 6a81fbb..0d0e102 100644
--- a/src/bin/butck.rs
+++ b/src/bin/butck.rs
@@ -3,11 +3,11 @@ use std::process::exit;
use butchunker::{
chunker::{
context::ButckContext,
- entry::{entry, print_help, print_version},
rw::error::{ButckRWError, ButckRWErrorKind},
},
- log::init_logger,
+ entry::{entry, print_help, print_version},
special_argument, special_flag,
+ utils::log::init_logger,
};
use just_progress::{progress, renderer};
use log::error;
@@ -104,6 +104,10 @@ fn handle_entry_result(r: Result<(), ButckRWError>) {
ButckRWErrorKind::ChunkFailed(_chunk_failed) => error!("Chunk failed"),
ButckRWErrorKind::IOError(error) => error!("IO error: {}", error),
ButckRWErrorKind::InvalidBidxFormat => error!("Invalid bidx format"),
+ ButckRWErrorKind::ChunkingFailed(reason) => error!("Chunking failed: {}", reason),
+ ButckRWErrorKind::IndexFileWriteFailed(reason) => {
+ error!("Failed to write index file: {}", reason)
+ }
},
}
}
diff --git a/src/bin/butckrepo-guide.rs b/src/bin/butckrepo-guide.rs
deleted file mode 100644
index d694ba5..0000000
--- a/src/bin/butckrepo-guide.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-use colored::Colorize;
-
-fn main() {
- println!("Welcome to Butchunker!");
- println!(
- "Please add your policy crates to the `{}` directory",
- "./policy/".bright_green()
- );
- println!(
- "Then run `{}` to update the policy registry",
- "cargo run --bin butckrepo-refresh".bright_green()
- );
-}
diff --git a/src/bin/butckrepo-refresh.rs b/src/bin/butckrepo-refresh.rs
index 9184efb..2b3d841 100644
--- a/src/bin/butckrepo-refresh.rs
+++ b/src/bin/butckrepo-refresh.rs
@@ -19,8 +19,8 @@ async fn main() {
println!("Updating policies ...");
let (mut lib_rs_template, mut cargo_toml_template) = {
- let lib_rs_template_path = current_dir.join("policy/_policies/src/lib.rs.t");
- let cargo_toml_template_path = current_dir.join("policy/_policies/Cargo.toml.t");
+ let lib_rs_template_path = current_dir.join(LIB_RS_TEMPLATE_PATH);
+ let cargo_toml_template_path = current_dir.join(CARGO_TOML_TEMPLATE_PATH);
let lib_rs_content = fs::read_to_string(&lib_rs_template_path)
.await
@@ -65,7 +65,10 @@ async fn main() {
tmpl_param!(lib_rs_template, policy_count = cargo_toml_pathes.len());
- let collect_futures = cargo_toml_pathes.iter().map(collect).collect::<Vec<_>>();
+ let collect_futures = cargo_toml_pathes
+ .iter()
+ .map(|path| collect(path))
+ .collect::<Vec<_>>();
for policy in futures::future::join_all(collect_futures).await {
let Some(policy) = policy else { continue };
@@ -96,8 +99,12 @@ async fn main() {
crate_name = policy.crate_name,
stream_struct_id = stream_struct_id
) },
- policy_names { (
- name = policy.crate_name,
+ match_arms_stream_display { (
+ crate_name = policy.crate_name,
+ stream_struct_id = stream_struct_id
+ ) },
+ stream_policy_names { (
+ name = policy.crate_name
) }
});
} else {
@@ -120,8 +127,15 @@ async fn main() {
crate_name = policy.crate_name,
stream_struct_id = stream_struct_id
) },
+ match_arms_stream_display { (
+ crate_name = policy.crate_name,
+ stream_struct_id = stream_struct_id
+ ) },
policy_names { (
name = policy.crate_name,
+ ) },
+ stream_policy_names { (
+ name = policy.crate_name
) }
});
}
@@ -162,7 +176,9 @@ struct CollectedPolicy {
stream_struct_id: Option<String>,
}
-async fn collect(policy_crate_path: &PathBuf) -> Option<CollectedPolicy> {
+type MatchedFuncInfo = (String, bool, Option<String>, bool, Option<String>);
+
+async fn collect(policy_crate_path: &Path) -> Option<CollectedPolicy> {
let lib_rs_path = policy_crate_path.join("src").join("lib.rs");
let lib_rs_content = fs::read_to_string(&lib_rs_path).await.ok()?;
@@ -227,9 +243,7 @@ async fn collect(policy_crate_path: &PathBuf) -> Option<CollectedPolicy> {
})
}
-fn collect_matched_func(
- lib_rs_content: &str,
-) -> Option<(String, bool, Option<String>, bool, Option<String>)> {
+fn collect_matched_func(lib_rs_content: &str) -> Option<MatchedFuncInfo> {
let syntax_tree = syn::parse_file(lib_rs_content).ok()?;
let mut matched_func = None;