fix: do it correctly

This commit is contained in:
Miles Murgaw committed 2023-07-14 20:41:27 -04:00
1 parent 41fd7a1040
commit d710b92696
7 files changed
+28 -21

No files matched your search

+2 -2
View File
@@ -12,8 +12,8 @@ pub struct Build {
} }
impl Build { impl Build {
pub fn build(self) -> Result<()> { pub fn build(self, bin: Option<PathBuf>) -> Result<()> {
let mut crate_config = crate::CrateConfig::new(self.build.bin)?; let mut crate_config = crate::CrateConfig::new(bin)?;
// change the release state. // change the release state.
crate_config.with_release(self.build.release); crate_config.with_release(self.build.release);
-8
View File
@@ -32,10 +32,6 @@ pub struct ConfigOptsBuild {
/// Space separated list of features to activate /// Space separated list of features to activate
#[clap(long)] #[clap(long)]
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
/// The binary to serve
#[clap(long)]
pub bin: Option<PathBuf>,
} }
#[derive(Clone, Debug, Default, Deserialize, Parser)] #[derive(Clone, Debug, Default, Deserialize, Parser)]
@@ -90,10 +86,6 @@ pub struct ConfigOptsServe {
/// Space separated list of features to activate /// Space separated list of features to activate
#[clap(long)] #[clap(long)]
pub features: Option<Vec<String>>, pub features: Option<Vec<String>>,
/// The binary to serve
#[clap(long)]
pub bin: Option<PathBuf>,
} }
/// Ensure the given value for `--public-url` is formatted correctly. /// Ensure the given value for `--public-url` is formatted correctly.
+2 -2
View File
@@ -6,8 +6,8 @@ use super::*;
pub struct Clean {} pub struct Clean {}
impl Clean { impl Clean {
pub fn clean(self) -> Result<()> { pub fn clean(self, bin: Option<PathBuf>) -> Result<()> {
let crate_config = crate::CrateConfig::new(None)?; let crate_config = crate::CrateConfig::new(bin)?;
let output = Command::new("cargo") let output = Command::new("cargo")
.arg("clean") .arg("clean")
+4
View File
@@ -36,6 +36,10 @@ pub struct Cli {
/// Enable verbose logging. /// Enable verbose logging.
#[clap(short)] #[clap(short)]
pub v: bool, pub v: bool,
/// Specify bin target
#[clap(global = true, long)]
pub bin: Option<PathBuf>,
} }
#[derive(Parser)] #[derive(Parser)]
+2 -2
View File
@@ -15,8 +15,8 @@ pub struct Serve {
} }
impl Serve { impl Serve {
pub async fn serve(self) -> Result<()> { pub async fn serve(self, bin: Option<PathBuf>) -> Result<()> {
let mut crate_config = crate::CrateConfig::new(self.serve.bin)?; let mut crate_config = crate::CrateConfig::new(bin)?;
// change the relase state. // change the relase state.
crate_config.with_hot_reload(self.serve.hot_reload); crate_config.with_hot_reload(self.serve.hot_reload);
+14 -3
View File
@@ -17,8 +17,19 @@ fn default_plugin() -> toml::Value {
} }
impl DioxusConfig { impl DioxusConfig {
pub fn load() -> crate::error::Result<Option<DioxusConfig>> { pub fn load(bin: Option<PathBuf>) -> crate::error::Result<Option<DioxusConfig>> {
let Ok(crate_dir) = crate::cargo::crate_root() else { return Ok(None); }; let crate_dir = crate::cargo::crate_root();
let crate_dir = match crate_dir {
Ok(dir) => {
if let Some(bin) = bin {
dir.join(bin)
} else {
dir
}
}
Err(_) => return Ok(None),
};
// we support either `Dioxus.toml` or `Cargo.toml` // we support either `Dioxus.toml` or `Cargo.toml`
let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else { let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else {
@@ -177,7 +188,7 @@ pub enum ExecutableType {
impl CrateConfig { impl CrateConfig {
pub fn new(bin: Option<PathBuf>) -> Result<Self> { pub fn new(bin: Option<PathBuf>) -> Result<Self> {
let dioxus_config = DioxusConfig::load()?.unwrap_or_default(); let dioxus_config = DioxusConfig::load(bin.clone())?.unwrap_or_default();
let crate_root = crate::cargo::crate_root()?; let crate_root = crate::cargo::crate_root()?;
+4 -4
View File
@@ -13,7 +13,7 @@ async fn main() -> anyhow::Result<()> {
set_up_logging(); set_up_logging();
let _dioxus_config = DioxusConfig::load() let _dioxus_config = DioxusConfig::load(args.bin.clone())
.map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))? .map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))?
.unwrap_or_else(|| { .unwrap_or_else(|| {
log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config"); log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
@@ -30,15 +30,15 @@ async fn main() -> anyhow::Result<()> {
.map_err(|e| anyhow!("🚫 Translation of HTML into RSX failed: {}", e)), .map_err(|e| anyhow!("🚫 Translation of HTML into RSX failed: {}", e)),
Build(opts) => opts Build(opts) => opts
.build() .build(args.bin.clone())
.map_err(|e| anyhow!("🚫 Building project failed: {}", e)), .map_err(|e| anyhow!("🚫 Building project failed: {}", e)),
Clean(opts) => opts Clean(opts) => opts
.clean() .clean(args.bin.clone())
.map_err(|e| anyhow!("🚫 Cleaning project failed: {}", e)), .map_err(|e| anyhow!("🚫 Cleaning project failed: {}", e)),
Serve(opts) => opts Serve(opts) => opts
.serve() .serve(args.bin.clone())
.await .await
.map_err(|e| anyhow!("🚫 Serving project failed: {}", e)), .map_err(|e| anyhow!("🚫 Serving project failed: {}", e)),