Skip to content

Commit

Permalink
Added yes and scope
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Nov 19, 2024
1 parent 7fb5b21 commit 6048d29
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
4 changes: 3 additions & 1 deletion crates/turborepo-lib/src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use turborepo_telemetry::events::command::CommandEventBuilder;
use turborepo_ui::{color, BOLD, GREY};

use crate::{
commands::{bin, generate, ls, prune, run::get_signal, CommandBase},
commands::{bin, generate, link, ls, prune, run::get_signal, CommandBase},
daemon::DaemonError,
query,
rewrite_json::RewriteError,
Expand Down Expand Up @@ -45,6 +45,8 @@ pub enum Error {
#[diagnostic(transparent)]
Ls(#[from] ls::Error),
#[error(transparent)]
Link(#[from] link::Error),
#[error(transparent)]
#[diagnostic(transparent)]
Prune(#[from] prune::Error),
#[error(transparent)]
Expand Down
19 changes: 16 additions & 3 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,12 @@ pub enum Command {
#[clap(long)]
no_gitignore: bool,

/// The scope, i.e. Vercel team, that you are linking
#[clap(long)]
scope: Option<String>,
/// Answer yes to all prompts (default false)
#[clap(long, short)]
yes: bool,
/// Specify what should be linked (default "remote cache")
#[clap(long, value_enum, default_value_t = LinkTarget::RemoteCache)]
target: LinkTarget,
Expand Down Expand Up @@ -1299,23 +1305,30 @@ pub async fn run(
}
Command::Link {
no_gitignore,
scope,
yes,
target,
} => {
CommandEventBuilder::new("link")
.with_parent(&root_telemetry)
.track_call();

if cli_args.team.is_some() {
warn!("team flag does not set the scope for linking. Use --scope instead.");
}

if cli_args.test_run {
println!("Link test run successful");
return Ok(0);
}

let modify_gitignore = !*no_gitignore;
let to = *target;
let yes = *yes;
let scope = scope.clone();
let mut base = CommandBase::new(cli_args, repo_root, version, color_config);

if let Err(err) = link::link(&mut base, modify_gitignore, to).await {
error!("error: {}", err.to_string())
}
link::link(&mut base, scope, modify_gitignore, yes, to).await?;

Ok(0)
}
Expand Down
24 changes: 19 additions & 5 deletions crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ pub(crate) async fn verify_caching_enabled<'a>(

pub async fn link(
base: &mut CommandBase,
scope: Option<String>,
modify_gitignore: bool,
yes: bool,
target: LinkTarget,
) -> Result<(), Error> {
let homedir_path = home_dir().ok_or_else(|| Error::HomeDirectoryNotFound)?;
Expand All @@ -183,8 +185,10 @@ pub async fn link(
REMOTE_CACHING_URL
);

if !should_link_remote_cache(base, &repo_root_with_tilde)? {
return Err(Error::NotLinking);
if !yes {
if !should_link_remote_cache(base, &repo_root_with_tilde)? {
return Err(Error::NotLinking);
}
}

let user_response = api_client
Expand All @@ -203,7 +207,17 @@ pub async fn link(
.await
.map_err(Error::TeamsRequest)?;

let selected_team = select_team(base, &teams_response.teams)?;
let selected_team = if let Some(team_slug) = scope {
SelectedTeam::Team(
teams_response
.teams
.iter()
.find(|team| team.slug == team_slug)
.ok_or_else(|| Error::TeamNotFound(team_slug.to_string()))?,
)
} else {
select_team(base, &teams_response.teams)?
};

let team_id = match selected_team {
SelectedTeam::User => user_response.user.id.as_str(),
Expand Down Expand Up @@ -632,7 +646,7 @@ mod test {
)
.unwrap();

link::link(&mut base, false, LinkTarget::RemoteCache)
link::link(&mut base, None, false, false, LinkTarget::RemoteCache)
.await
.unwrap();

Expand Down Expand Up @@ -707,7 +721,7 @@ mod test {
)
.unwrap();

link::link(&mut base, false, LinkTarget::Spaces)
link::link(&mut base, None, false, false, LinkTarget::Spaces)
.await
.unwrap();

Expand Down
9 changes: 8 additions & 1 deletion crates/turborepo-lib/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,14 @@ impl Diagnostic for RemoteCacheDiagnostic {
return;
};
stopped.await.unwrap();
let link_res = link(&mut base, false, crate::cli::LinkTarget::RemoteCache).await;
let link_res = link(
&mut base,
None,
false,
false,
crate::cli::LinkTarget::RemoteCache,
)
.await;
resume.send(()).unwrap();
link_res
};
Expand Down
8 changes: 8 additions & 0 deletions turborepo-tests/integration/tests/command-link.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ Link Test Run
$ ${TURBO} link --__test-run
Link test run successful

$ ${TURBO} link --__test-run --yes
Link test run successful

$ ${TURBO} link --__test-run --team=my-team
WARNING team flag does not set the scope for linking. Use --scope instead.
Link test run successful


0 comments on commit 6048d29

Please sign in to comment.