Skip to content

Commit

Permalink
Started work on link. Got prompt working
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jan 26, 2023
1 parent f1a9fab commit 77fecaa
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ clap = { version = "4.0.22", features = ["derive"] }
clap_complete = "4.0.6"
config = "0.13"
console = "0.15.5"
dialoguer = "0.10.3"
dirs-next = "2.0.0"
dunce = "1.0"
env_logger = "0.10.0"
Expand Down
12 changes: 9 additions & 3 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use log::{debug, error};
use serde::Serialize;

use crate::{
commands::{bin, login, logout, CommandBase},
commands::{bin, link, login, logout, CommandBase},
get_version,
shim::{RepoMode, RepoState},
ui::UI,
Expand Down Expand Up @@ -456,8 +456,14 @@ pub async fn run(repo_state: Option<RepoState>) -> Result<Payload> {

Ok(Payload::Rust(Ok(0)))
}
Command::Link { .. }
| Command::Unlink { .. }
Command::Link { no_gitignore } => {
let base = CommandBase::new(clap_args, repo_root)?;

link::link(base)?;

Ok(Payload::Rust(Ok(0)))
}
Command::Unlink { .. }
| Command::Daemon { .. }
| Command::Prune { .. }
| Command::Run(_) => Ok(Payload::Go(Box::new(clap_args))),
Expand Down
50 changes: 50 additions & 0 deletions crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use anyhow::{anyhow, Result};
use dialoguer::Confirm;
use dirs_next::home_dir;

use crate::{
commands::CommandBase,
ui::{BOLD, CYAN, GREY, UNDERLINE},
};

pub fn link(base: CommandBase) -> Result<()> {
let homedir_path = home_dir().ok_or_else(|| anyhow!("could not find home directory."))?;
let homedir = homedir_path.to_string_lossy();
println!(">>> Remote Caching");
println!();
println!(" Remote Caching shares your cached Turborepo task outputs and logs across");
println!(" all your team’s Vercel projects. It also can share outputs");
println!(" with other services that enable Remote Caching, like CI/CD systems.");
println!(" This results in faster build times and deployments for your team.");
println!(
" For more info, see {}",
UNDERLINE.apply_to("https://turbo.build/repo/docs/core-concepts/remote-caching")
);
println!();

let repo_root_with_tilde = base.repo_root.to_string_lossy().replacen(&*homedir, "~", 1);

if !should_link(&base, &repo_root_with_tilde)? {
return Err(anyhow!("canceled"));
}

if base.user_config()?.token.is_none() {
return Err(anyhow!(
"User not found. Please login to Turborepo first by running {}.",
BOLD.apply_to("`npx turbo login`")
));
}

Ok(())
}

fn should_link(base: &CommandBase, location: &str) -> Result<bool> {
let prompt = format!(
"{}{} {}",
BOLD.apply_to(GREY.apply_to("? ")),
BOLD.apply_to("Would you like to enable Remote Caching for"),
base.ui.apply(BOLD.apply_to(CYAN.apply_to(location)))
);

Ok(Confirm::new().with_prompt(prompt).interact()?)
}
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
};

pub(crate) mod bin;
pub(crate) mod link;
pub(crate) mod login;
pub(crate) mod logout;

Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ lazy_static! {
pub static ref GREY: Style = Style::new().dim();
pub static ref CYAN: Style = Style::new().cyan();
pub static ref BOLD: Style = Style::new().bold();
pub static ref UNDERLINE: Style = Style::new().underlined();
}

pub const RESET: &str = "\x1b[0m";
Expand Down

0 comments on commit 77fecaa

Please sign in to comment.