This commit is contained in:
2025-05-13 10:03:13 +03:00
parent 29ccc54a4d
commit 1e914aa56d
6 changed files with 172 additions and 13 deletions

View File

@@ -72,7 +72,12 @@ fn main() -> Result<()> {
.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("collection")
.short("c".chars().next().unwrap())
.long("collection")
.takes_value(true)
.required(false)
.help("Name of the collection (export all if not specified)"))
.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')")),
)
@@ -350,13 +355,13 @@ fn main() -> Result<()> {
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 output_path_str = matches.value_of("output").unwrap();
let output_path = Path::new(output_path_str);
let doctree_name = matches.value_of("doctree").unwrap_or("default");
let collection_name_opt = matches.value_of("collection");
if debug_mode {
println!("DEBUG: Exporting collection '{}' from doctree '{}' to IPFS output path '{}'",
collection_name, doctree_name, output_path);
println!("DEBUG: Handling export_to_ipfs command.");
}
// Create a storage with the specified doctree name
@@ -377,14 +382,36 @@ fn main() -> Result<()> {
// 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)));
match collection_name_opt {
Some(collection_name) => {
// Export a specific collection
if debug_mode {
println!("DEBUG: Exporting specific collection '{}'", collection_name);
}
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)));
}
None => {
// Export all collections
if debug_mode {
println!("DEBUG: Exporting all collections.");
}
let collections = doctree.list_collections();
if collections.is_empty() {
println!("No collections found to export.");
} else {
println!("Exporting the following collections:");
for collection_name in collections {
println!("- {}", collection_name);
if let Err(e) = doctree.export_collection_to_ipfs(&collection_name, output_path) {
eprintln!("Error exporting collection '{}': {}", collection_name, e);
} else {
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");