This commit is contained in:
2025-05-03 05:52:42 +04:00
parent 28a7ef3a94
commit 2fae059512
3 changed files with 197 additions and 47 deletions

View File

@@ -7,6 +7,12 @@ fn main() -> Result<()> {
.version("0.1.0")
.author("Your Name")
.about("A tool to manage document collections")
.arg(
Arg::with_name("debug")
.long("debug")
.help("Enable debug logging")
.takes_value(false)
)
.subcommand(
SubCommand::with_name("scan")
.about("Scan a directory for .collection files and create collections")
@@ -65,9 +71,16 @@ fn main() -> Result<()> {
)
.get_matches();
// Check if debug mode is enabled
let debug_mode = matches.is_present("debug");
// Handle subcommands
if let Some(matches) = matches.subcommand_matches("scan") {
let path = matches.value_of("path").unwrap();
if debug_mode {
println!("DEBUG: Scanning path: {}", path);
}
let doctree_name = matches.value_of("doctree").unwrap_or("default");
println!("Recursively scanning for collections in: {}", path);
@@ -89,17 +102,21 @@ fn main() -> Result<()> {
} else if let Some(matches) = matches.subcommand_matches("list") {
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Listing collections for doctree: {}", doctree_name);
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
// Create a DocTree with the specified doctree name
let doctree = DocTree::builder()
.with_storage(storage)
.with_doctree_name(doctree_name)
.build()?;
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
let collections = doctree.list_collections();
// Get collections directly from Redis to avoid debug output from DocTree
let collections = storage.list_all_collections()?;
if collections.is_empty() {
println!("No collections found in doctree '{}'", doctree_name);
@@ -115,9 +132,19 @@ fn main() -> Result<()> {
let format = matches.value_of("format").unwrap_or("markdown");
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Getting page '{}' from collection '{}' in doctree '{}' with format '{}'",
page, collection.unwrap_or("(default)"), doctree_name, format);
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
// Create a DocTree with the specified doctree name
let mut doctree = DocTree::builder()
@@ -140,9 +167,19 @@ fn main() -> Result<()> {
let page = matches.value_of("page").unwrap();
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Getting HTML for page '{}' from collection '{}' in doctree '{}'",
page, collection, doctree_name);
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
// Create a DocTree with the specified doctree name
let mut doctree = DocTree::builder()
@@ -157,10 +194,24 @@ fn main() -> Result<()> {
println!("{}", html);
} else if let Some(matches) = matches.subcommand_matches("info") {
let doctree_name = matches.value_of("doctree").unwrap_or("default");
let collection_name = matches.value_of("collection");
if debug_mode {
if let Some(name) = collection_name {
println!("DEBUG: Getting info for collection '{}' in doctree '{}'", name, doctree_name);
} else {
println!("DEBUG: Getting info for all collections in doctree '{}'", doctree_name);
}
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
// Create a DocTree with the specified doctree name
let mut doctree = DocTree::builder()
@@ -270,9 +321,17 @@ fn main() -> Result<()> {
let collection = matches.value_of("collection").unwrap();
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Deleting collection '{}' from doctree '{}'", collection, doctree_name);
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
// Create a DocTree with the specified doctree name
let mut doctree = DocTree::builder()
@@ -286,9 +345,18 @@ fn main() -> Result<()> {
} else if let Some(matches) = matches.subcommand_matches("reset") {
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Resetting all collections in doctree '{}'", doctree_name);
}
// Create a storage with the specified doctree name
let storage = RedisStorage::new("redis://localhost:6379")?;
storage.set_doctree_name(doctree_name);
storage.set_debug(debug_mode);
if debug_mode {
println!("DEBUG: Connected to Redis storage");
}
// Create a DocTree with the specified doctree name
let mut doctree = DocTree::builder()