mod adapter;
mod cargo;
mod feature;
mod resource;
use std::path::{Path, PathBuf};
use crate::context::Context;
use crate::error::CliResult;
use crate::scaffold::{Scaffold, ensure_module_import, rustfmt};
pub use adapter::{AdapterOptions, run as run_adapter};
pub use feature::{FeatureOptions, run as run_feature};
pub use resource::{ResourceOptions, run as run_resource};
pub(super) fn resolve_start(path: Option<PathBuf>) -> PathBuf {
path.unwrap_or_else(|| std::env::current_dir().expect("cwd"))
}
pub(super) fn finish(s: Scaffold, dry_run: bool, base: &Path, summary: &str) -> CliResult<()> {
let report = s.apply(dry_run)?;
if !dry_run {
rustfmt(&report.rust_files());
}
println!("{summary}");
report.print(base);
Ok(())
}
pub(super) fn wire_into_app(
ctx: &Context,
s: &mut Scaffold,
use_path: &str,
ident: &str,
require_token: Option<&str>,
) -> Option<PathBuf> {
let module_rs = ctx.current_app_module()?;
if !module_rs.is_file() {
return None;
}
if let Some(token) = require_token {
let source = std::fs::read_to_string(&module_rs).ok()?;
if !source.contains(token) {
return None;
}
}
s.edit(&module_rs, ensure_module_import(use_path, ident));
Some(module_rs)
}