Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose Args and new run_wasm_with_css_with_args #37

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ Normally you can run just `cargo run` to run the main binary of the current pack
The equivalent of that is `cargo run-wasm --package name_of_current_package`
";

struct Args {
pub struct Args {
help: bool,
profile: Option<String>,
build_only: bool,
@@ -68,12 +68,14 @@ struct Args {

impl Args {
pub fn from_env() -> Result<Self, String> {
let mut args = Arguments::from_env();
Self::from_args(Arguments::from_env())
}

pub fn from_args(mut args: Arguments) -> Result<Self, String> {
let release_arg = args.contains("--release") || args.contains("-r");
let profile_arg: Option<String> = args.opt_value_from_str("--profile").unwrap();
if release_arg && profile_arg.is_some() {
return Err(r#"conflicting usage of --profile and --release.
return Err(r#"conflicting usage of `--profile` and `--release`.
The `--release` flag is the same as `--profile=release`.
Remove one flag or the other to continue."#
.to_owned());
@@ -157,6 +159,17 @@ Remove one flag or the other to continue."#
/// cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
/// ```
pub fn run_wasm_with_css(css: &str) {
let args = match Args::from_env() {
Ok(args) => args,
Err(err) => {
println!("{}\n\n{}", err, HELP);
return;
}
};
run_wasm_with_css_and_args(css, args)
}

pub fn run_wasm_with_css_and_args(css: &str, args: Args) {
// validate css
//
// Someone could easily get around this with some extra spaces
@@ -167,13 +180,6 @@ pub fn run_wasm_with_css(css: &str) {
)
}

let args = match Args::from_env() {
Ok(args) => args,
Err(err) => {
println!("{}\n\n{}", err, HELP);
return;
}
};
if args.help {
println!("{}", HELP);
return;