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

feat: turbo info command for debugging #9368

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
22 changes: 17 additions & 5 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use turborepo_ui::{ColorConfig, GREY};
use crate::{
cli::error::print_potential_tasks,
commands::{
bin, config, daemon, generate, link, login, logout, ls, prune, query, run, scan, telemetry,
unlink, CommandBase,
bin, config, daemon, generate, info, link, login, logout, ls, prune, query, run, scan,
telemetry, unlink, CommandBase,
},
get_version,
run::watch::WatchClient,
Expand Down Expand Up @@ -475,9 +475,7 @@ impl Args {
}
}

/// Defines the subcommands for CLI. NOTE: If we change the commands in Go,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but saw it mentioning Go so ✂️

/// we must change these as well to avoid accidentally passing the
/// --single-package flag into non-build commands.
/// Defines the subcommands for CLI
#[derive(Subcommand, Clone, Debug, PartialEq)]
pub enum Command {
/// Get the path to the Turbo binary
Expand Down Expand Up @@ -570,6 +568,8 @@ pub enum Command {
#[clap(long)]
invalidate: bool,
},
/// Print debugging information
Info,
/// Prepare a subset of your monorepo.
Prune {
#[clap(hide = true, long)]
Expand Down Expand Up @@ -1214,6 +1214,18 @@ pub async fn run(
generate::run(tag, command, &args, child_event)?;
Ok(0)
}
Command::Info => {
CommandEventBuilder::new("info")
.with_parent(&root_telemetry)
.track_call();
let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config);

match info::run(base).await {
Ok(()) => {}
Err(e) => println!("Command failed. Please file a GitHub Issue.\n{}", e),
anthonyshew marked this conversation as resolved.
Show resolved Hide resolved
}
Ok(0)
}
Command::Telemetry { command } => {
let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry);
event.track_call();
Expand Down
93 changes: 93 additions & 0 deletions crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use std::{env, io};

use sysinfo::{System, SystemExt};
use thiserror::Error;
use turborepo_repository::{package_json::PackageJson, package_manager::PackageManager};

use super::CommandBase;
use crate::{DaemonConnector, DaemonConnectorError};

#[derive(Debug, Error)]
pub enum Error {
#[error("could not get path to turbo binary: {0}")]
NoCurrentExe(#[from] io::Error),
}

pub async fn run(base: CommandBase) -> Result<(), Error> {
let system = System::new_all();
let connector = DaemonConnector::new(false, false, &base.repo_root);
let daemon_status = match connector.connect().await {
Ok(_status) => "Running",
Err(DaemonConnectorError::NotRunning) => "Not running",
Err(_e) => "Error getting status",
};

let package_manager = match PackageJson::load(&base.repo_root.join_component("package.json")) {
Ok(package_json) => {
match PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root) {
Ok(pm) => pm.to_string(),
Err(_) => "Not found".to_owned(),
}
}
Err(_) => "Not found".to_owned(),
};
Comment on lines +25 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some Rust code golf. I'd recommend manually committing this because Rustfmt will probably disagree with this formatting

Suggested change
let package_manager = match PackageJson::load(&base.repo_root.join_component("package.json")) {
Ok(package_json) => {
match PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root) {
Ok(pm) => pm.to_string(),
Err(_) => "Not found".to_owned(),
}
}
Err(_) => "Not found".to_owned(),
};
let package_manager = PackageJson::load(&base.repo_root.join_component("package.json"))
.and_then(|package_json| PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root))
.map_or_else(|_| "Not found".to_owned(), |pm| pm.to_string());


println!("CLI:");
println!(" Version: {}", base.version);
println!(
" Location: {}",
std::env::current_exe()?.to_string_lossy()
);
println!(" Daemon status: {}", daemon_status);
println!(" Package manager: {}", package_manager);
println!();

println!("Platform:");
println!(" Architecture: {}", std::env::consts::ARCH);
println!(" Operating system: {}", std::env::consts::OS);
println!(
" Available memory (MB): {}",
system.available_memory() / 1024 / 1024
);
println!(" Available CPU cores: {}", num_cpus::get());
println!();

println!("Environment:");
println!(" CI: {:#?}", turborepo_ci::Vendor::get_name());
println!(
" Terminal (TERM): {}",
env::var("TERM").unwrap_or_else(|_| "unknown".to_owned())
);

println!(
" Terminal program (TERM_PROGRAM): {}",
env::var("TERM_PROGRAM").unwrap_or_else(|_| "unknown".to_owned())
);
println!(
" Terminal program version (TERM_PROGRAM_VERSION): {}",
env::var("TERM_PROGRAM_VERSION").unwrap_or_else(|_| "unknown".to_owned())
);
println!(
" Shell (SHELL): {}",
env::var("SHELL").unwrap_or_else(|_| "unknown".to_owned())
);
println!(" stdin: {}", turborepo_ci::is_ci());
println!();

println!("Turborepo System Environment Variables:");
for (key, value) in env::vars() {
// Don't print sensitive information
if key == "TURBO_TEAM"
|| key == "TURBO_TEAMID"
|| key == "TURBO_TOKEN"
|| key == "TURBO_API"
{
continue;
}
if key.starts_with("TURBO_") {
println!(" {}: {}", key, value);
}
}

Ok(())
}
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 @@ -15,6 +15,7 @@ pub(crate) mod bin;
pub(crate) mod config;
pub(crate) mod daemon;
pub(crate) mod generate;
pub(crate) mod info;
pub(crate) mod link;
pub(crate) mod login;
pub(crate) mod logout;
Expand Down
1 change: 1 addition & 0 deletions turborepo-tests/integration/tests/no-args.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Make sure exit code is 2 when no args are passed
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
info Print debugging information
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL
Expand Down
2 changes: 2 additions & 0 deletions turborepo-tests/integration/tests/turbo-help.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Test help flag
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
info Print debugging information
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL
Expand Down Expand Up @@ -139,6 +140,7 @@ Test help flag
link Link your local directory to a Vercel organization and enable remote caching
login Login to your Vercel account
logout Logout to your Vercel account
info Print debugging information
prune Prepare a subset of your monorepo
run Run tasks across projects in your monorepo
query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL
Expand Down
Loading