Skip to content

Commit

Permalink
flags: move raw+jobs flags to only commands that install
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Dec 13, 2023
1 parent fff00ef commit 91c1207
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 102 deletions.
6 changes: 1 addition & 5 deletions e2e/test_local
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ assert_raises() {
fi
}

assert_raises "rtx uninstall [email protected]"
rtx i [email protected] [email protected]

assert "rtx local" "#:schema ../../schema/rtx.json
env_file = '.test-env'
Expand Down Expand Up @@ -57,8 +57,6 @@ if [[ "$(rtx exec -- shfmt --version)" != "v3.5.0" ]]; then
exit 1
fi

assert_raises "rtx uninstall [email protected]"

rtx local [email protected]
assert "rtx local" "#:schema ../../schema/rtx.json
env_file = '.test-env'
Expand Down Expand Up @@ -101,8 +99,6 @@ tiny-ref = \"https://github.com/rtx-plugins/rtx-tiny#df03b6719dd465d565bb6627394

export RTX_DEFAULT_CONFIG_FILENAME=.MISSING

assert_raises "rtx uninstall [email protected]"

rtx local
assert "rtx local" "#python 3.11.1 3.10.9 # foo
shellcheck sub-0.1:0.10.0
Expand Down
22 changes: 0 additions & 22 deletions src/cli/args/jobs.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/cli/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pub mod env_var;
pub mod jobs;
pub mod log_level;
pub mod quiet;
pub mod raw;
pub mod tool;
pub mod verbose;
pub mod yes;
14 changes: 0 additions & 14 deletions src/cli/args/raw.rs

This file was deleted.

24 changes: 21 additions & 3 deletions src/cli/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cli::args::tool::{ToolArg, ToolArgParser};
use crate::config::Config;

use crate::shell::{get_shell, ShellType};
use crate::toolset::{Toolset, ToolsetBuilder};
use crate::toolset::{InstallOptions, Toolset, ToolsetBuilder};

/// Exports env vars to activate rtx a single time
///
Expand All @@ -21,15 +21,33 @@ pub struct Env {
#[clap(value_name = "TOOL@VERSION", value_parser = ToolArgParser)]
tool: Vec<ToolArg>,

/// Number of jobs to run in parallel
/// [default: 4]
#[clap(long, short, env = "RTX_JOBS", verbatim_doc_comment)]
jobs: Option<usize>,

/// Output in JSON format
#[clap(long, short = 'J', overrides_with = "shell")]
json: bool,

/// Directly pipe stdin/stdout/stderr from plugin to user
/// Sets --jobs=1
#[clap(long, overrides_with = "jobs")]
raw: bool,
}

impl Env {
pub fn run(self, config: Config) -> Result<()> {
pub fn run(self, mut config: Config) -> Result<()> {
if self.raw {
config.settings.raw = true;
}
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;
let opts = InstallOptions {
force: false,
jobs: self.jobs,
raw: self.raw,
};
ts.install_arg_versions(&config, &opts)?;

if self.json {
self.output_json(config, ts)
Expand Down
24 changes: 21 additions & 3 deletions src/cli/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::cmd;
use crate::config::Config;
use crate::env;

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

/// Execute a command with tool(s) set
///
Expand Down Expand Up @@ -42,12 +42,30 @@ pub struct Exec {
/// Change to this directory before executing the command
#[clap(short = 'C', value_hint = ValueHint::DirPath, long)]
pub cd: Option<PathBuf>,

/// Number of jobs to run in parallel
/// [default: 4]
#[clap(long, short, env = "RTX_JOBS", verbatim_doc_comment)]
pub jobs: Option<usize>,

/// Directly pipe stdin/stdout/stderr from plugin to user
/// Sets --jobs=1
#[clap(long, overrides_with = "jobs")]
pub raw: bool,
}

impl Exec {
pub fn run(self, config: Config) -> Result<()> {
pub fn run(self, mut config: Config) -> Result<()> {
if self.raw {
config.settings.raw = true;
}
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;
let opts = InstallOptions {
force: false,
jobs: self.jobs,
raw: self.raw,
};
ts.install_arg_versions(&config, &opts)?;

let (program, args) = parse_command(&env::SHELL, &self.command, &self.c);
let env = ts.env_with_path(&config);
Expand Down
29 changes: 25 additions & 4 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cli::args::tool::{ToolArg, ToolArgParser};
use crate::config::Config;

use crate::toolset::{
ToolVersion, ToolVersionOptions, ToolVersionRequest, Toolset, ToolsetBuilder,
InstallOptions, ToolVersion, ToolVersionOptions, ToolVersionRequest, Toolset, ToolsetBuilder,
};
use crate::ui::multi_progress_report::MultiProgressReport;

Expand All @@ -28,13 +28,26 @@ pub struct Install {
#[clap(long, short, requires = "tool")]
force: bool,

/// Number of jobs to run in parallel
/// [default: 4]
#[clap(long, short, env = "RTX_JOBS", verbatim_doc_comment)]
jobs: Option<usize>,

/// Directly pipe stdin/stdout/stderr from plugin to user
/// Sets --jobs=1
#[clap(long, overrides_with = "jobs")]
raw: bool,

/// Show installation output
#[clap(long, short, action = clap::ArgAction::Count)]
verbose: u8,
}

impl Install {
pub fn run(self, config: Config) -> Result<()> {
pub fn run(self, mut config: Config) -> Result<()> {
if self.raw {
config.settings.raw = true;
}
match &self.tool {
Some(runtime) => self.install_runtimes(config, runtime)?,
None => self.install_missing_runtimes(config)?,
Expand All @@ -53,7 +66,15 @@ impl Install {
warn!("specify a version with `rtx install <PLUGIN>@<VERSION>`");
return Ok(());
}
ts.install_versions(&config, tool_versions, &mpr, self.force)
ts.install_versions(&config, tool_versions, &mpr, &self.install_opts())
}

fn install_opts(&self) -> InstallOptions {
InstallOptions {
force: self.force,
jobs: self.jobs,
raw: self.raw,
}
}

fn get_requested_tool_versions(
Expand Down Expand Up @@ -116,7 +137,7 @@ impl Install {
return Ok(());
}
let mpr = MultiProgressReport::new(&config.settings);
ts.install_versions(&config, versions, &mpr, self.force)?;
ts.install_versions(&config, versions, &mpr, &self.install_opts())?;
Ok(())
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,10 @@ impl Cli {
.arg_required_else_help(true)
.subcommand_required(true)
.after_long_help(AFTER_LONG_HELP)
.arg(args::jobs::Jobs::arg())
.arg(args::log_level::Debug::arg())
.arg(args::log_level::LogLevel::arg())
.arg(args::log_level::Trace::arg())
.arg(args::quiet::Quiet::arg())
.arg(args::raw::Raw::arg())
.arg(args::verbose::Verbose::arg())
.arg(args::yes::Yes::arg()),
)
Expand All @@ -203,12 +201,6 @@ impl Cli {
return version::Version {}.run(config);
}
let matches = self.command.get_matches_from(args);
if let Some(jobs) = matches.get_one::<usize>("jobs") {
config.settings.jobs = *jobs;
}
if let Some(raw) = matches.get_one::<bool>("raw") {
config.settings.raw = *raw;
}
if let Some(true) = matches.get_one::<bool>("yes") {
config.settings.yes = true;
}
Expand Down
24 changes: 21 additions & 3 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use console::style;
use crate::cli::args::tool::{ToolArg, ToolArgParser};
use crate::config::Config;
use crate::shell::get_shell;
use crate::toolset::{ToolSource, ToolsetBuilder};
use crate::toolset::{InstallOptions, ToolSource, ToolsetBuilder};

/// Sets a tool version for the current shell session
///
Expand All @@ -16,19 +16,37 @@ pub struct Shell {
#[clap(value_name = "TOOL@VERSION", value_parser = ToolArgParser)]
tool: Vec<ToolArg>,

/// Number of jobs to run in parallel
/// [default: 4]
#[clap(long, short, env = "RTX_JOBS", verbatim_doc_comment)]
jobs: Option<usize>,

/// Directly pipe stdin/stdout/stderr from plugin to user
/// Sets --jobs=1
#[clap(long, overrides_with = "jobs")]
raw: bool,

/// Removes a previously set version
#[clap(long, short)]
unset: bool,
}

impl Shell {
pub fn run(self, config: Config) -> Result<()> {
pub fn run(self, mut config: Config) -> Result<()> {
if self.raw {
config.settings.raw = true;
}
if !config.is_activated() {
err_inactive()?;
}

let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
ts.install_arg_versions(&config)?;
let opts = InstallOptions {
force: false,
jobs: self.jobs,
raw: self.raw,
};
ts.install_arg_versions(&config, &opts)?;

let shell = get_shell(None).expect("no shell detected");

Expand Down
24 changes: 21 additions & 3 deletions src/cli/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::config::Config;
use crate::plugins::Plugin;
use crate::runtime_symlinks;
use crate::shims;
use crate::toolset::{ToolVersion, ToolsetBuilder};
use crate::toolset::{InstallOptions, ToolVersion, ToolsetBuilder};
use crate::ui::multi_progress_report::MultiProgressReport;
use crate::ui::progress_report::ProgressReport;

Expand All @@ -27,10 +27,23 @@ pub struct Upgrade {
/// Just print what would be done, don't actually do it
#[clap(long, short = 'n', verbatim_doc_comment)]
dry_run: bool,

/// Number of jobs to run in parallel
/// [default: 4]
#[clap(long, short, env = "RTX_JOBS", verbatim_doc_comment)]
jobs: Option<usize>,

/// Directly pipe stdin/stdout/stderr from plugin to user
/// Sets --jobs=1
#[clap(long, overrides_with = "jobs")]
raw: bool,
}

impl Upgrade {
pub fn run(self, config: Config) -> Result<()> {
pub fn run(self, mut config: Config) -> Result<()> {
if self.raw {
config.settings.raw = true;
}
let mut ts = ToolsetBuilder::new().with_args(&self.tool).build(&config)?;
let tool_set = self
.tool
Expand Down Expand Up @@ -77,7 +90,12 @@ impl Upgrade {
}
return Ok(());
}
ts.install_versions(config, new_versions, &mpr, false)?;
let opts = InstallOptions {
force: false,
jobs: self.jobs,
raw: self.raw,
};
ts.install_versions(config, new_versions, &mpr, &opts)?;
for (tool, tv) in to_remove {
let mut pr = mpr.add();
self.uninstall_old_version(config, tool.clone(), &tv, &mut pr)?;
Expand Down
Loading

0 comments on commit 91c1207

Please sign in to comment.