Skip to content
Merged
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ Creating /Users/justjavac/.dvm

### .dvmrc

You can let dvm to writing config to current directery by add the `--local` flag to `dvm use`. Afterwards, `dvm use`, `dvm install` will use the version
You can let dvm to writing config to current directery by add the `--local` flag
to `dvm use`. Afterwards, `dvm use`, `dvm install` will use the version
specified in the `.dvmrc` file if no version is supplied on the command line.

For example, to make dvm default to the `1.17.0` release for the current
Expand Down Expand Up @@ -158,7 +159,8 @@ You can install unzip via `brew install unzip` on MacOS or

### Powershell on Windows is **required**

Currently, we use PowerShell profile to set environment variables due to various reasons, so it's required.
Currently, we use PowerShell profile to set environment variables due to various
reasons, so it's required.

## License

Expand Down
6 changes: 3 additions & 3 deletions src/commands/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use semver::Version;

use super::install;

pub fn exec(meta: &mut DvmMeta, command: &str, verison: Option<&str>) -> Result<()> {
pub fn exec(meta: &mut DvmMeta, version: Option<String>, args: Vec<String>) -> Result<()> {
let versions = remote_versions().expect("Failed to get remote versions");
let version = verison.map(|v| v.to_string()).unwrap_or_else(|| "latest".to_string());
let version = version.unwrap_or_else(|| "latest".to_string());

let version = if is_exact_version(&version) {
version
Expand Down Expand Up @@ -45,7 +45,7 @@ pub fn exec(meta: &mut DvmMeta, command: &str, verison: Option<&str>) -> Result<
}

let mut cmd = std::process::Command::new(executable_path)
.arg(command)
.args(args)
.stderr(Stdio::inherit())
.stdout(Stdio::inherit())
.stdin(Stdio::inherit())
Expand Down
49 changes: 45 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ mod meta;
mod utils;
pub mod version;

use std::env;

use clap::{CommandFactory, Parser};
use clap_complete::Shell;
use clap_derive::{Parser, Subcommand};
Expand Down Expand Up @@ -122,7 +124,7 @@ enum Commands {
command: Option<String>,

#[clap(help = "The version to use", long, short)]
verison: Option<String>,
deno_version: Option<String>,
},

#[clap(about = "Clean dvm cache")]
Expand Down Expand Up @@ -156,9 +158,44 @@ pub enum AliasCommands {
}

pub fn main() {
let cli = Cli::parse();
let mut meta = DvmMeta::new();

let args: Vec<String> = env::args().collect();
if args.len() > 1 {
if args[1] == "exec" {
if args.len() > 2 {
let version: Option<String>;
if args[2] == "--version" || args[2] == "-V" {
if args.len() > 3 {
version = Some(args[3].clone());
commands::exec::exec(&mut meta, version, args[4..].to_vec()).unwrap();
} else {
eprintln!("A version should be followed after {}", args[2]);
std::process::exit(1)
}
} else if args[2].starts_with("--version=") || args[2].starts_with("-V=") {
version = Some(
args[2]
.trim_start_matches("-V=")
.trim_start_matches("--version=")
.to_string(),
);
commands::exec::exec(&mut meta, version, args[3..].to_vec()).unwrap();
} else {
version = None;
commands::exec::exec(&mut meta, version, args[2..].to_vec()).unwrap();
}
} else {
// TODO(CGQAQ): print help
}
}
return;
}

println!("hello?");

let cli = Cli::parse();

let result = match cli.command {
Commands::Completions { shell } => commands::completions::exec(&mut Cli::command(), shell),
Commands::Info => commands::info::exec(),
Expand All @@ -172,8 +209,12 @@ pub fn main() {
Commands::Deactivate => commands::deactivate::exec(),
Commands::Doctor => commands::doctor::exec(&mut meta),
Commands::Upgrade { alias } => commands::upgrade::exec(&mut meta, alias),
Commands::Exec { command, verison } => {
commands::exec::exec(&mut meta, command.unwrap_or_default().as_str(), verison.as_deref())
Commands::Exec {
command: _,
deno_version: _,
} => {
/* unused */
Ok(())
}
Commands::Clean => commands::clean::exec(&mut meta),
Commands::Registry { registry } => commands::registry::exec(&mut meta, registry),
Expand Down