wip: restructure the entire CLI

This commit is contained in:
Jonathan Kelley committed 2022-01-08 22:57:47 -05:00
1 parent 6b991bf184
commit 6c351efbf0
27 files changed
+259 -232

No files matched your search

+35 -82
View File
@@ -1,97 +1,50 @@
mod builder;
mod cargo;
mod cli;
mod config;
mod error;
mod logging;
mod helpers {
pub mod extract_svgs;
pub mod to_component;
pub mod translate;
}
mod watch;
mod develop {
pub mod develop;
pub mod draw;
pub mod events;
pub mod studio;
}
use std::path::PathBuf;
use dioxus_studio::*;
use structopt::StructOpt;
#[async_std::main]
#[tokio::main]
async fn main() -> Result<()> {
let args = Trunk::from_args();
set_up_logging();
let args = Args::from_args();
match args.command {
LaunchCommand::Develop(cfg) => {
develop::develop::develop(cfg).await?;
}
// LaunchCommand::Develop(cfg) => develop::studio::start(cfg).await?,
LaunchCommand::Build(opts) => {
let mut cfg = CrateConfig::new()?;
cfg.with_build_options(&opts);
builder::build(&cfg)?;
match args.action {
TrunkSubcommands::Build(_) => {
//
}
LaunchCommand::Translate(cfg) => {
let TranslateOptions {
file,
text,
component,
} = cfg;
TrunkSubcommands::Translate(opts) => {
// let TranslateOptions {
// file,
// text,
// component,
// } = cfg;
match component {
true => {
let f = helpers::to_component::convert_html_to_component(&text.unwrap())?;
println!("{}", f);
}
false => {
let renderer = match (file, text) {
(None, Some(text)) => translate::translate_from_html_to_rsx(&text, false)?,
(Some(file), None) => translate::translate_from_html_file(&file)?,
_ => panic!("Must select either file or text - not both or none!"),
};
// match component {
// true => {
// let f = helpers::to_component::convert_html_to_component(&text.unwrap())?;
// println!("{}", f);
// }
// false => {
// let renderer = match (file, text) {
// (None, Some(text)) => translate::translate_from_html_to_rsx(&text, false)?,
// (Some(file), None) => translate::translate_from_html_file(&file)?,
// _ => panic!("Must select either file or text - not both or none!"),
// };
println!("{}", renderer);
}
}
// println!("{}", renderer);
// }
// }
}
_ => {
todo!("Those commands are not yet supported");
TrunkSubcommands::Clean(_) => {
//
}
TrunkSubcommands::Config(_) => {
//
}
TrunkSubcommands::Serve(_) => {
//
}
}
Ok(())
}
/// Build, bundle & ship your Rust WASM application to the web.
#[derive(StructOpt)]
#[structopt(name = "trunk")]
struct Args {
#[structopt(subcommand)]
command: TrunkSubcommands,
/// Path to the Trunk config file [default: Trunk.toml]
#[structopt(long, parse(from_os_str), env = "TRUNK_CONFIG")]
pub config: Option<PathBuf>,
/// Enable verbose logging.
#[structopt(short)]
pub v: bool,
}
#[derive(StructOpt)]
enum TrunkSubcommands {
/// Build the Rust WASM app and all of its assets.
Build(cmd::build::Build),
/// Build & watch the Rust WASM app and all of its assets.
Watch(cmd::watch::Watch),
/// Build, watch & serve the Rust WASM app and all of its assets.
Serve(cmd::serve::Serve),
/// Clean output artifacts.
Clean(cmd::clean::Clean),
/// Trunk config controls.
Config(cmd::config::Config),
}