Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 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 @@
}
}

/// 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 @@
#[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 @@
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;

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Rust lints

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused `std::result::Result` that must be used

Check warning on line 1222 in crates/turborepo-lib/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused `std::result::Result` that must be used

Ok(0)
}
Command::Telemetry { command } => {
let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry);
event.track_call();
Expand Down
88 changes: 88 additions & 0 deletions crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use std::{env, io};

use sysinfo::{System, SystemExt};
use thiserror::Error;

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> {
Copy link
Contributor

Choose a reason for hiding this comment

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

ITG (non blocking follow up): Separate the data from the display logic to make this more unit-test friendly and support additional output formats like JSON.

Something like:

struct TurboInfo {
    package_manager: String,
    daemon_status: String,
    ...
}

And then have turbo_info.print() to actually write the data to stdout

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",
};

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

Check failure on line 31 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

empty string literal in `println!`

println!("Package managers:");
println!(" npm version: {}", "TODO");

Check failure on line 34 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

literal with an empty format string
println!(" yarn version: {}", "TODO");

Check failure on line 35 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

literal with an empty format string
println!(" pnpm version: {}", "TODO");

Check failure on line 36 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

literal with an empty format string
println!(" bun version: {}", "TODO");

Check failure on line 37 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

literal with an empty format string
println!("");

Check failure on line 38 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

empty string literal in `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!("");

Check failure on line 48 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

empty string literal in `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!("");

Check failure on line 70 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

empty string literal in `println!`

println!("Turborepo System Environment Variables:");
for (key, value) in env::vars() {
// Don't print sensitive information
if key == "TURBO_TEAM".to_string()

Check failure on line 75 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

this creates an owned instance just for comparison
|| key == "TURBO_TEAMID".to_string()

Check failure on line 76 in crates/turborepo-lib/src/commands/info.rs

View workflow job for this annotation

GitHub Actions / Rust lints

this creates an owned instance just for comparison
|| key == "TURBO_TOKEN".to_string()
|| key == "TURBO_API".to_string()
{
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
Loading