cli: add server-data-dir and extensions-dir on command-shell (#228287)

This commit is contained in:
Connor Peet 2024-09-12 08:06:42 -07:00 committed by GitHub
parent 498870d214
commit 061cbf557f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View File

@ -226,6 +226,9 @@ pub struct ServeWebArgs {
#[derive(Args, Debug, Clone)]
pub struct CommandShellArgs {
#[clap(flatten)]
pub server_args: BaseServerArgs,
/// Listen on a socket instead of stdin/stdout.
#[clap(long)]
pub on_socket: bool,
@ -638,6 +641,9 @@ pub struct ExistingTunnelArgs {
#[derive(Args, Debug, Clone, Default)]
pub struct TunnelServeArgs {
#[clap(flatten)]
pub server_args: BaseServerArgs,
/// Optional details to connect to an existing tunnel
#[clap(flatten, next_help_heading = Some("ADVANCED OPTIONS"))]
pub tunnel: ExistingTunnelArgs,
@ -661,7 +667,10 @@ pub struct TunnelServeArgs {
/// If set, the user accepts the server license terms and the server will be started without a user prompt.
#[clap(long)]
pub accept_server_license_terms: bool,
}
#[derive(Args, Debug, Clone, Default)]
pub struct BaseServerArgs {
/// Requests that extensions be preloaded and installed on connecting servers.
#[clap(long)]
pub install_extension: Vec<String>,
@ -675,8 +684,8 @@ pub struct TunnelServeArgs {
pub extensions_dir: Option<String>,
}
impl TunnelServeArgs {
pub fn apply_to_server_args(&self, csa: &mut CodeServerArgs) {
impl BaseServerArgs {
pub fn apply_to(&self, csa: &mut CodeServerArgs) {
csa.install_extensions
.extend_from_slice(&self.install_extension);

View File

@ -155,6 +155,8 @@ pub async fn command_shell(ctx: CommandContext, args: CommandShellArgs) -> Resul
code_server_args: (&ctx.args).into(),
};
args.server_args.apply_to(&mut params.code_server_args);
let mut listener: Box<dyn AsyncRWAccepter> =
match (args.on_port.first(), &args.on_host, args.on_socket) {
(_, _, true) => {
@ -440,7 +442,7 @@ pub async fn serve(ctx: CommandContext, gateway_args: TunnelServeArgs) -> Result
legal::require_consent(&paths, gateway_args.accept_server_license_terms)?;
let mut csa = (&args).into();
gateway_args.apply_to_server_args(&mut csa);
gateway_args.server_args.apply_to(&mut csa);
let result = serve_with_csa(paths, log, gateway_args, csa, TUNNEL_CLI_LOCK_NAME).await;
drop(no_sleep);
@ -587,7 +589,7 @@ async fn serve_with_csa(
Ok(SingletonConnection::Client(stream)) => {
debug!(log, "starting as client to singleton");
if gateway_args.name.is_some()
|| !gateway_args.install_extension.is_empty()
|| !gateway_args.server_args.install_extension.is_empty()
|| gateway_args.tunnel.tunnel_id.is_some()
{
warning!(