Skip to content

Commit

Permalink
feat: turbo info command for debugging (#9368)
Browse files Browse the repository at this point in the history
### Description

A command to provide debugging information for reproductions or
otherwise understand a machine better. Output will look something close
to this.

```
CLI:
   Version: 2.2.4-canary.4
   Location: /Users/anthonyshew/projects/open/turbo/target/debug/turbo
   Daemon status: Running
   Package manager: pnpm

Platform:
   Architecture: aarch64
   Operating system: macos
   Available memory (MB): 13598
   Available CPU cores: 10

Environment:
   CI: None
   Terminal (TERM): xterm-256color
   Terminal program (TERM_PROGRAM): tmux
   Terminal program version (TERM_PROGRAM_VERSION): 3.4
   Shell (SHELL): /bin/zsh
   stdin: false

Turborepo System Environment Variables:
   TURBO_INVOCATION_DIR: /Users/anthonyshew/projects/open/turbo
```

### Testing Instructions

Try it out!
  • Loading branch information
anthonyshew authored Nov 7, 2024
1 parent c03735d commit 52f6f46
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
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 @@ -474,9 +474,7 @@ impl Args {
}
}

/// Defines the subcommands for CLI. NOTE: If we change the commands in Go,
/// 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 @@ -569,6 +567,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 @@ -1223,6 +1223,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 @@ -141,6 +142,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

0 comments on commit 52f6f46

Please sign in to comment.