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

Merged
merged 10 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 14 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,15 @@ 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);

info::run(base).await;
Ok(0)
}
Command::Telemetry { command } => {
let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry);
event.track_call();
Expand Down
75 changes: 75 additions & 0 deletions crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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) {
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 = PackageJson::load(&base.repo_root.join_component("package.json"))
.ok()
.and_then(|package_json| {
PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root).ok()
})
.map_or_else(|| "Not found".to_owned(), |pm| pm.to_string());

println!("CLI:");
println!(" Version: {}", base.version);

let exe_path = std::env::current_exe().map_or_else(
|e| format!("Cannot determine current binary: {e}").to_owned(),
|path| path.to_string_lossy().into_owned(),
);

println!(" Path to executable: {}", exe_path);
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!();
}
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