...
This commit is contained in:
@@ -4,3 +4,5 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
doctree = { path = "../doctree" }
|
||||
clap = "3.2.25"
|
||||
|
@@ -1,3 +1,78 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use doctree::{DocTree, RedisStorage, Result};
|
||||
use std::path::Path;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let matches = App::new("DocTree CLI")
|
||||
.version("0.1.0")
|
||||
.author("Your Name")
|
||||
.about("A tool to manage document collections")
|
||||
.subcommand(
|
||||
SubCommand::with_name("scan")
|
||||
.about("Scan a directory and create a collection")
|
||||
.arg(Arg::with_name("path").required(true).help("Path to the directory"))
|
||||
.arg(Arg::with_name("name").required(true).help("Name of the collection")),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("list")
|
||||
.about("List collections"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("get")
|
||||
.about("Get page content")
|
||||
.arg(Arg::with_name("collection").required(true).help("Name of the collection"))
|
||||
.arg(Arg::with_name("page").required(true).help("Name of the page")),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("html")
|
||||
.about("Get page content as HTML")
|
||||
.arg(Arg::with_name("collection").required(true).help("Name of the collection"))
|
||||
.arg(Arg::with_name("page").required(true).help("Name of the page")),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
// Create a Redis storage instance
|
||||
let storage = RedisStorage::new("redis://localhost:6379")?;
|
||||
|
||||
// Create a DocTree instance
|
||||
let mut doctree = DocTree::builder()
|
||||
.with_storage(storage)
|
||||
.build()?;
|
||||
|
||||
// Handle subcommands
|
||||
if let Some(matches) = matches.subcommand_matches("scan") {
|
||||
let path = matches.value_of("path").unwrap();
|
||||
let name = matches.value_of("name").unwrap();
|
||||
|
||||
println!("Scanning directory: {}", path);
|
||||
doctree.add_collection(Path::new(path), name)?;
|
||||
println!("Collection '{}' created successfully", name);
|
||||
} else if let Some(_) = matches.subcommand_matches("list") {
|
||||
let collections = doctree.list_collections();
|
||||
|
||||
if collections.is_empty() {
|
||||
println!("No collections found");
|
||||
} else {
|
||||
println!("Collections:");
|
||||
for collection in collections {
|
||||
println!("- {}", collection);
|
||||
}
|
||||
}
|
||||
} else if let Some(matches) = matches.subcommand_matches("get") {
|
||||
let collection = matches.value_of("collection").unwrap();
|
||||
let page = matches.value_of("page").unwrap();
|
||||
|
||||
let content = doctree.page_get(Some(collection), page)?;
|
||||
println!("{}", content);
|
||||
} else if let Some(matches) = matches.subcommand_matches("html") {
|
||||
let collection = matches.value_of("collection").unwrap();
|
||||
let page = matches.value_of("page").unwrap();
|
||||
|
||||
let html = doctree.page_get_html(Some(collection), page)?;
|
||||
println!("{}", html);
|
||||
} else {
|
||||
println!("No command specified. Use --help for usage information.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user