aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Letan <contact@thomasletan.fr>2019-09-17 09:07:18 +0200
committerThomas Letan <contact@thomasletan.fr>2019-09-17 09:07:18 +0200
commit711a79188a10d92e05302ca2e2d6d6a5ce9dc50d (patch)
tree6b991c3522bb1f6ca841918bc80dbc30b4ebb8ff
parentfeature: Require to specify the language of the Book (diff)
feature: List dependencies of a celtchar document
We provide an additional command `deps' that basically print one dependency of —an ogmarkup document used to build a— celtchar document. This way, `celtchar deps' can be used e.g., in a Makefile. If a filename cannot be converted into a valid rust string, the message <invalid utf8 filename> is print.
-rw-r--r--app/src/main.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/app/src/main.rs b/app/src/main.rs
index 8b50d25..ea8fcbe 100644
--- a/app/src/main.rs
+++ b/app/src/main.rs
@@ -9,7 +9,7 @@ use std::path::PathBuf;
use clap::{App, SubCommand};
-use libceltchar::{Error, Zip, Project, EpubWriter};
+use libceltchar::{Loader, Error, Zip, Project, EpubWriter};
#[cfg(debug_assertions)]
use std::env::current_dir;
@@ -19,6 +19,24 @@ use libceltchar::Raise;
mod filesystem;
use crate::filesystem::{find_root, Fs};
+fn deps() -> Result<(), Error> {
+ let root = find_root()?;
+ let loader = Fs;
+ let project = loader.load_project(&root)?;
+
+ let mut files = vec![];
+
+ for mut chapter in project.chapters.into_iter() {
+ files.append(&mut chapter.content)
+ }
+
+ for file in files {
+ println!("{}", file.to_str().unwrap_or("<invalid utf8 filename>"));
+ }
+
+ Ok(())
+}
+
fn build(assets : &PathBuf) -> Result<(), Error> {
let root = find_root()?;
let loader = Fs;
@@ -50,6 +68,8 @@ fn main() -> Result<(), Error> {
.about("Create a new celtchar document"))
.subcommand(SubCommand::with_name("build")
.about("Build a celtchar document"))
+ .subcommand(SubCommand::with_name("deps")
+ .about("List dependencies of a celtchar document"))
.get_matches();
let (subcommand, _args) = matches.subcommand();
@@ -58,6 +78,7 @@ fn main() -> Result<(), Error> {
match subcommand {
"build" => build(&assets)?,
+ "deps" => deps()?,
_ => unimplemented!(),
}