This commit is contained in:
2025-05-13 09:19:45 +03:00
parent 7fa4125dc0
commit dbd44043cb
3 changed files with 148 additions and 76 deletions

View File

@@ -69,6 +69,13 @@ fn main() -> Result<()> {
.about("Delete all collections from Redis")
.arg(Arg::with_name("doctree").long("doctree").takes_value(true).help("Name of the doctree (default: 'default')")),
)
.subcommand(
SubCommand::with_name("export_to_ipfs")
.about("Export a collection to IPFS")
.arg(Arg::with_name("collection").required(true).help("Name of the collection"))
.arg(Arg::with_name("output").required(true).help("Output directory for IPFS export"))
.arg(Arg::with_name("doctree").long("doctree").takes_value(true).help("Name of the doctree (default: 'default')")),
)
.get_matches();
// Check if debug mode is enabled
@@ -342,6 +349,43 @@ fn main() -> Result<()> {
println!("Deleting collection '{}' from Redis in doctree '{}'...", collection, doctree_name);
doctree.delete_collection(collection)?;
println!("Collection '{}' deleted successfully", collection);
} else if let Some(matches) = matches.subcommand_matches("export_to_ipfs") {
let collection_name = matches.value_of("collection").unwrap();
let output_path = matches.value_of("output").unwrap();
let doctree_name = matches.value_of("doctree").unwrap_or("default");
if debug_mode {
println!("DEBUG: Exporting collection '{}' from doctree '{}' to IPFS output path '{}'",
collection_name, doctree_name, output_path);
}
// 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()
.with_storage(storage)
.with_doctree_name(doctree_name)
.build()?;
// Load collections from Redis
doctree.load_collections_from_redis()?;
// Get the collection
let collection = doctree.get_collection(collection_name)?;
// Call the synchronous export_collection_to_ipfs_sync function from the doctree crate
let output_path = Path::new(output_path);
doctree.export_collection_to_ipfs(collection_name, output_path)?;
println!("Successfully exported collection '{}' to IPFS and generated metadata CSV at {:?}.", collection_name, output_path.join(format!("{}.csv", collection_name)));
} else if let Some(matches) = matches.subcommand_matches("reset") {
let doctree_name = matches.value_of("doctree").unwrap_or("default");
@@ -370,6 +414,6 @@ fn main() -> Result<()> {
} else {
println!("No command specified. Use --help for usage information.");
}
Ok(())
}