Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec: default to "latest" if no version specified #1247

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 13 additions & 4 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use crate::cli::args::tool::{ToolArg, ToolArgParser};
use crate::cmd;
use crate::config::Config;
use crate::env;

use crate::toolset::{InstallOptions, ToolsetBuilder};
use crate::toolset::{InstallOptions, ToolVersionRequest, ToolsetBuilder};

/// Execute a command with tool(s) set
///
Expand Down Expand Up @@ -55,7 +54,18 @@ pub struct Exec {
}

impl Exec {
pub fn run(self, config: &Config) -> Result<()> {
pub fn run(mut self, config: &Config) -> Result<()> {
// if no version is specified, default to "latest"
self.tool
.iter_mut()
.filter(|t| t.tvr.is_none())
.for_each(|t| {
t.tvr = Some(ToolVersionRequest::Version(
t.plugin.clone(),
"latest".into(),
))
});

let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(config)?;
let opts = InstallOptions {
force: false,
Expand Down Expand Up @@ -146,7 +156,6 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(

#[cfg(test)]
mod tests {

#[test]
fn test_exec_ok() {
assert_cli!("exec", "--", "echo");
Expand Down
Loading