Skip to content

Pass args after -- to the executable during run and serve #4212

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions packages/cli/src/build/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ impl AppBuilder {
}
}

#[allow(clippy::too_many_arguments)]
pub(crate) async fn open(
&mut self,
devserver_ip: SocketAddr,
Expand All @@ -425,6 +426,7 @@ impl AppBuilder {
open_browser: bool,
always_on_top: bool,
build_id: BuildId,
args: &[String],
) -> Result<()> {
let krate = &self.build;

Expand Down Expand Up @@ -501,7 +503,7 @@ impl AppBuilder {
| Platform::MacOS
| Platform::Windows
| Platform::Linux
| Platform::Liveview => self.open_with_main_exe(envs)?,
| Platform::Liveview => self.open_with_main_exe(envs, args)?,
};

self.builds_opened += 1;
Expand Down Expand Up @@ -732,12 +734,13 @@ impl AppBuilder {
/// paths right now, but they will when we start to enable things like swift integration.
///
/// Server/liveview/desktop are all basically the same, though
fn open_with_main_exe(&mut self, envs: Vec<(&str, String)>) -> Result<()> {
fn open_with_main_exe(&mut self, envs: Vec<(&str, String)>, args: &[String]) -> Result<()> {
let main_exe = self.app_exe();

tracing::debug!("Opening app with main exe: {main_exe:?}");

let mut child = Command::new(main_exe)
.args(args)
.envs(envs)
.env_remove("CARGO_MANIFEST_DIR") // running under `dx` shouldn't expose cargo-only :
.stderr(Stdio::piped())
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ pub(crate) struct ServeArgs {
#[clap(long)]
pub(crate) cross_origin_policy: bool,

/// Additional arguments to pass to the executable
#[clap(long)]
pub(crate) args: Vec<String>,

/// Sets the interval in seconds that the CLI will poll for file changes on WSL.
#[clap(long, default_missing_value = "2")]
pub(crate) wsl_file_poll_interval: Option<u16>,
Expand All @@ -78,6 +74,10 @@ pub(crate) struct ServeArgs {

#[clap(flatten)]
pub(crate) targets: BuildArgs,

/// Additional arguments to pass to the executable
#[clap(last = true)]
pub(crate) args: Vec<String>,
}

impl ServeArgs {
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/serve/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub(crate) struct AppServer {
pub(crate) proxied_port: Option<u16>,
pub(crate) cross_origin_policy: bool,

// The arguments that should be forwarded to the app when it is opened
pub(crate) open_args: Vec<String>,

// Additional plugin-type tools
pub(crate) tw_watcher: tokio::task::JoinHandle<Result<()>>,
}
Expand Down Expand Up @@ -151,6 +154,8 @@ impl AppServer {
.map(|server| AppBuilder::start(&server, build_mode))
.transpose()?;

let open_args = args.args;

let tw_watcher = TailwindCli::serve(
client.build.package_manifest_dir(),
client.build.config.application.tailwind_input.clone(),
Expand Down Expand Up @@ -187,6 +192,7 @@ impl AppServer {
cross_origin_policy,
fullstack,
tw_watcher,
open_args,
};

// Only register the hot-reload stuff if we're watching the filesystem
Expand Down Expand Up @@ -546,6 +552,7 @@ impl AppServer {
false,
false,
BuildId::SERVER,
&self.open_args,
)
.await?;
}
Expand All @@ -560,6 +567,7 @@ impl AppServer {
open_browser,
self.always_on_top,
BuildId::CLIENT,
&self.open_args,
)
.await?;

Expand Down
Loading