|
| 1 | +use super::exec::*; |
| 2 | +use crate::error::ProtoCliError; |
| 3 | +use crate::session::ProtoSession; |
| 4 | +use clap::Args; |
| 5 | +use starbase::AppResult; |
| 6 | +use starbase_shell::ShellType; |
| 7 | + |
| 8 | +#[derive(Args, Clone, Debug)] |
| 9 | +pub struct ShellArgs { |
| 10 | + #[arg(help = "Tools to initialize")] |
| 11 | + tools: Vec<String>, |
| 12 | + |
| 13 | + #[arg(long, help = "Shell to start a session for")] |
| 14 | + shell: Option<ShellType>, |
| 15 | +} |
| 16 | + |
| 17 | +#[tracing::instrument(skip_all)] |
| 18 | +pub async fn shell(session: ProtoSession, args: ShellArgs) -> AppResult { |
| 19 | + // Detect the shell that we need to activate for |
| 20 | + let shell_type = match args.shell { |
| 21 | + Some(value) => value, |
| 22 | + None => ShellType::try_detect()?, |
| 23 | + }; |
| 24 | + |
| 25 | + // Define the interactive command to use |
| 26 | + let command = match shell_type { |
| 27 | + ShellType::Ash => "ash -i", |
| 28 | + ShellType::Bash => "bash -i", |
| 29 | + ShellType::Elvish => "elvish", |
| 30 | + ShellType::Fish => "fish --interactive", |
| 31 | + ShellType::Ion => "ion", |
| 32 | + ShellType::Murex => "murex", |
| 33 | + ShellType::Nu => "nu --interactive", |
| 34 | + ShellType::Pwsh => "pwsh -Interactive -NoLogo", |
| 35 | + ShellType::Sh => "sh", |
| 36 | + ShellType::Xonsh => "xonsh --interactive", |
| 37 | + ShellType::Zsh => "zsh --interactive", |
| 38 | + ShellType::PowerShell => { |
| 39 | + return Err(ProtoCliError::ShellPowerShellNotSupported.into()); |
| 40 | + } |
| 41 | + }; |
| 42 | + |
| 43 | + // Passthrough to exec |
| 44 | + exec( |
| 45 | + session, |
| 46 | + ExecArgs { |
| 47 | + tools_from_config: args.tools.is_empty(), |
| 48 | + tools: args.tools, |
| 49 | + raw: false, |
| 50 | + shell: None, |
| 51 | + command: command |
| 52 | + .split_whitespace() |
| 53 | + .map(|arg| arg.to_owned()) |
| 54 | + .collect(), |
| 55 | + }, |
| 56 | + ) |
| 57 | + .await |
| 58 | +} |
0 commit comments