Skip to content

Commit

Permalink
Add limited activate command
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Mar 30, 2023
1 parent bf80d74 commit 2591fde
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bin/huak/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Cli {
#[derive(Subcommand)]
#[clap(rename_all = "kebab-case")]
pub enum Commands {
/// Activate the virtual envionrment.
Activate,
/// Add dependencies to the project.
Add {
#[arg(num_args = 1.., required = true)]
Expand Down Expand Up @@ -180,7 +182,7 @@ impl Cli {
..Default::default()
};
match self.command {
Commands::Config { command } => config(command),
Commands::Activate => activate(operation_config),
Commands::Add {
dependencies,
group,
Expand All @@ -206,6 +208,7 @@ impl Cli {
operation_config.clean_options = Some(options);
clean(operation_config)
}
Commands::Config { command } => config(command),
Commands::Fix { trailing } => {
operation_config.lint_options = Some(LintOptions {
args: trailing,
Expand Down Expand Up @@ -311,6 +314,10 @@ impl Cli {
}
}

fn activate(operation_config: OperationConfig) -> HuakResult<()> {
ops::activate_venv(&operation_config)
}

fn add(
dependencies: Vec<Dependency>,
group: Option<String>,
Expand Down
28 changes: 28 additions & 0 deletions src/huak/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ pub struct OperationConfig {
pub clean_options: Option<CleanOptions>,
}

pub fn activate_venv(config: &OperationConfig) -> HuakResult<()> {
let mut terminal = create_terminal(&config.terminal_options);
let venv = resolve_venv(config, &mut terminal)?;
#[cfg(unix)]
let mut cmd = Command::new("bash");
#[cfg(windows)]
let mut cmd = Command::new("powershell");
#[cfg(unix)]
cmd.args([
"--init-file",
&format!("{}", venv.executables_dir_path().join("activate").display()),
"-i",
]);
#[cfg(windows)]
cmd.args([
"-executionpolicy",
"bypass",
"-NoExit",
"-NoLogo",
"-File",
&format!(
"{}",
venv.executables_dir_path().join("activate.ps1").display()
),
]);
terminal.run_command(&mut cmd)
}

pub fn add_project_dependencies(
dependencies: &[String],
config: &OperationConfig,
Expand Down

0 comments on commit 2591fde

Please sign in to comment.