use clap::Parser;
use color_eyre::Result;
+use std::fs;
pub fn get_opts() -> Result<Options> {
let opts = Options::try_from(Opts::parse())?;
source.build_dir()
}
+
+pub fn new_site(opts: &Options) -> Result<()> {
+ macro_rules! exist_or_build(
+ ($p:expr) => {
+ if !$p.exists() {
+ fs::create_dir_all(&$p)?;
+ }
+ };
+ );
+
+ macro_rules! write_default (
+ ($p:expr, $m:literal) => {
+ let path = opts.pattern.join($p).join("default.meta");
+ fs::write(path, $m)?;
+ };
+ );
+
+ exist_or_build!(opts.root);
+ exist_or_build!(opts.source);
+ exist_or_build!(opts.pattern);
+
+ exist_or_build!(opts.pattern.join("base"));
+ exist_or_build!(opts.pattern.join("body"));
+ exist_or_build!(opts.pattern.join("head"));
+ exist_or_build!(opts.pattern.join("foot"));
+
+ write_default!("base", "<html>\n&{head}\n&{body}\n&{foot}\n</html>\n");
+ write_default!("body", "<body>\n&{SOURCE}\n</body>\n");
+ write_default!("head", "<head>\n<title>HELLO WORLD</title>\n</head>\n");
+ write_default!("foot", "<foot>\n${footer}\n</foot>\n");
+
+ let path = opts.source.join("hello_world.meta");
+ fs::write(path, "${ footer = 'made using metaforge' }\n# it works\ncall `metaforge -h` for help, or read the [readme](https://huck.website/code/metaforge)\n")?;
+
+ Ok(())
+}
/// Pattern directory [CURRENT_DIR/pattern]
#[arg(short, long, value_name = "PATTERN_DIR")]
pub pattern: Option<String>,
+ /// Create a new skeleton directory
+ #[arg(long, default_value_t = false)]
+ pub new: bool,
/// Enable extra output.
/// Repeated flags give more info
#[arg(short, long, action = clap::ArgAction::Count)]
pub undefined: bool,
pub clean: bool,
pub no_pandoc: bool,
+ pub new: bool,
}
impl Options {
undefined: false,
clean: false,
no_pandoc: false,
+ new: false,
}
}
}
options.undefined = value.undefined;
options.clean = value.clean;
options.no_pandoc = value.no_pandoc;
+ options.new = value.new;
if let Some(root) = value.root.as_deref() {
options.root = PathBuf::from(root).canonicalize()?;
--- /dev/null
+<html>
+<head>
+<title>HELLO WORLD</title>
+</head>
+<body>
+<h1 id="it-works">it works</h1>
+<p>call <code>metaforge -h</code> for help, or read the <a
+href="https://huck.website/code/metaforge">readme</a></p>
+</body>
+<foot>made using metaforge</foot>
+</html>