Repository: denoland/deno
Pull request: fix(tunnel): rename `--connected` to `--tunnel` and better handle `DENO_DEPLOY_TOKEN` env variable


Changed files:
filename: cli/args/flags.rs
patch: @@ -755,7 +755,7 @@ pub struct Flags {
   pub eszip: bool,
   pub node_conditions: Vec<String>,
   pub preload: Vec<String>,
-  pub connected: bool,
+  pub tunnel: bool,
 }
 
 #[derive(Clone, Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
@@ -3370,7 +3370,7 @@ fn run_args(command: Command, top_level: bool) -> Command {
     .arg(env_file_arg())
     .arg(no_code_cache_arg())
     .arg(coverage_arg())
-    .arg(connected_arg())
+    .arg(tunnel_arg())
 }
 
 fn run_subcommand() -> Command {
@@ -3447,7 +3447,7 @@ Start a server defined in server.ts, watching for changes and running on port 50
     )
     .arg(env_file_arg())
     .arg(no_code_cache_arg())
-    .arg(connected_arg())
+    .arg(tunnel_arg())
 }
 
 fn task_subcommand() -> Command {
@@ -3500,7 +3500,7 @@ Evaluate a task from string:
           ).action(ArgAction::SetTrue)
       )
       .arg(node_modules_dir_arg())
-      .arg(connected_arg())
+      .arg(tunnel_arg())
   })
 }
 
@@ -4644,9 +4644,11 @@ fn no_check_arg() -> Arg {
     .help_heading(TYPE_CHECKING_HEADING)
 }
 
-fn connected_arg() -> Arg {
-  Arg::new("connected")
-    .long("connected")
+fn tunnel_arg() -> Arg {
+  Arg::new("tunnel")
+    .long("tunnel")
+    .alias("connected")
+    .short('t')
     .hide(true)
     .num_args(0..=1)
     .require_equals(true)
@@ -5749,7 +5751,7 @@ fn run_parse(
   runtime_args_parse(flags, matches, true, true, true)?;
   ext_arg_parse(flags, matches);
 
-  flags.connected = matches.get_flag("connected");
+  flags.tunnel = matches.get_flag("tunnel");
   flags.code_cache_enabled = !matches.get_flag("no-code-cache");
   let coverage_dir = matches.remove_one::<String>("coverage");
 
@@ -5821,7 +5823,7 @@ fn serve_parse(
   }
   flags.code_cache_enabled = !matches.get_flag("no-code-cache");
 
-  flags.connected = matches.get_flag("connected");
+  flags.tunnel = matches.get_flag("tunnel");
 
   let mut script_arg =
     matches.remove_many::<String>("script_arg").ok_or_else(|| {
@@ -5874,7 +5876,7 @@ fn task_parse(
     None
   };
 
-  flags.connected = matches.get_flag("connected");
+  flags.tunnel = matches.get_flag("tunnel");
 
   let mut task_flags = TaskFlags {
     cwd: matches.remove_one::<String>("cwd"),

filename: cli/main.rs
patch: @@ -658,11 +658,11 @@ async fn resolve_flags_and_init(
   load_env_variables_from_env_files(env_file_paths.as_ref(), flags.log_level);
 
   if deno_lib::args::has_flag_env_var("DENO_CONNECTED") {
-    flags.connected = true;
+    flags.tunnel = true;
   }
 
   // Tunnel sets up env vars and OTEL, so connect before everything else.
-  if flags.connected {
+  if flags.tunnel {
     if let Err(err) = initialize_tunnel(&flags).await {
       exit_for_error(err.context("Failed to start with --connected"));
     }
@@ -914,9 +914,9 @@ async fn auth_tunnel(
 ) -> Result<String, deno_core::anyhow::Error> {
   let mut args = vec!["deploy".to_string(), "tunnel-login".to_string()];
 
-  if let Some(token) = env_token {
+  if let Some(token) = &env_token {
     args.push("--token".to_string());
-    args.push(token);
+    args.push(token.clone());
   }
 
   let mut child = tokio::process::Command::new(env::current_exe()?)
@@ -928,7 +928,11 @@ async fn auth_tunnel(
     deno_runtime::exit(1);
   }
 
-  Ok(tools::deploy::get_token_entry()?.get_password()?)
+  if let Some(token) = env_token {
+    Ok(token)
+  } else {
+    Ok(tools::deploy::get_token_entry()?.get_password()?)
+  }
 }
 
 #[allow(clippy::print_stderr)]

filename: cli/tools/task.rs
patch: @@ -182,7 +182,7 @@ pub async fn execute_script(
   let progress_bar = factory.text_only_progress_bar();
   let mut env_vars = task_runner::real_env_vars();
 
-  if flags.connected {
+  if flags.tunnel {
     env_vars.insert("DENO_CONNECTED".into(), "1".into());
   }