Skip to content

Commit

Permalink
new: Add debug env command. (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Dec 22, 2023
1 parent 119fff1 commit e90cd1a
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#### 🚀 Updates

- Added a `proto debug env` command, for debugging basic env/store information.
- Updated version resolve errors to include the tool that failed.

#### ⚙️ Internal
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["crates/*"]
default-members = ["crates/cli"]

[workspace.dependencies]
anyhow = "1.0.75"
anyhow = "1.0.76"
cached = "0.46.1"
clap = "4.4.11"
clap_complete = "4.4.4"
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ pub enum DebugCommands {
about = "Debug all loaded .prototools config's for the current directory."
)]
Config(DebugConfigArgs),

#[command(name = "env", about = "Debug the current proto environment and store.")]
Env,
}

#[derive(Clone, Debug, Subcommand)]
Expand Down
84 changes: 84 additions & 0 deletions crates/cli/src/commands/debug/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::helpers::ProtoResource;
use crate::printer::Printer;
use proto_pdk_api::{HostArch, HostOS};
use starbase::system;
use starbase_styles::color;
use std::env;

#[system]
pub async fn env(proto: ResourceRef<ProtoResource>) {
let manager = proto.env.load_config_manager()?;
let mut printer = Printer::new();

// STORE

printer.named_section("Store", |p| {
p.entry("Root", color::path(&proto.env.root));
p.entry("Bins", color::path(&proto.env.bin_dir));
p.entry("Shims", color::path(&proto.env.shims_dir));
p.entry("Plugins", color::path(&proto.env.plugins_dir));
p.entry("Tools", color::path(&proto.env.tools_dir));
p.entry("Temp", color::path(&proto.env.temp_dir));
p.entry_map(
"Virtual",
proto
.env
.get_virtual_paths()
.iter()
.map(|(h, g)| (color::file(g.to_string_lossy()), color::path(h))),
None,
);
p.entry_list(
"Configs",
manager.files.iter().filter_map(|f| {
if f.exists {
Some(color::path(&f.path))
} else {
None
}
}),
None,
);

Ok(())
})?;

// ENV

printer.named_section("Environment", |p| {
p.entry(
"Proto version",
color::muted_light(env!("CARGO_PKG_VERSION")),
);
p.entry(
"Operating system",
color::muted_light(HostOS::from_env().to_string()),
);
p.entry(
"Architecture",
color::muted_light(HostArch::from_env().to_string()),
);
p.entry_map(
"Variables",
env::vars().filter_map(|(k, v)| {
if k.starts_with("PROTO_") {
Some((
color::id(k),
if v.contains('/') || v.contains('\\') {
color::path(v)
} else {
color::muted_light(v)
},
))
} else {
None
}
}),
None,
);

Ok(())
})?;

printer.flush();
}
2 changes: 2 additions & 0 deletions crates/cli/src/commands/debug/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod config;
mod env;

pub use config::*;
pub use env::*;
1 change: 1 addition & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async fn main() -> MainResult {
Commands::Completions(args) => app.execute_with_args(commands::completions, args),
Commands::Debug { command } => match command {
DebugCommands::Config(args) => app.execute_with_args(commands::debug::config, args),
DebugCommands::Env => app.execute(commands::debug::env),
},
Commands::Install(args) => app.execute_with_args(commands::install, args),
Commands::InstallGlobal(args) => app.execute_with_args(commands::install_global, args),
Expand Down
9 changes: 0 additions & 9 deletions crates/core/templates/unix/sh.tpl

This file was deleted.

11 changes: 0 additions & 11 deletions crates/core/templates/windows/cmd.tpl

This file was deleted.

3 changes: 0 additions & 3 deletions crates/core/templates/windows/macros.tpl

This file was deleted.

20 changes: 0 additions & 20 deletions crates/core/templates/windows/ps1.tpl

This file was deleted.

4 changes: 0 additions & 4 deletions crates/core/templates/windows/sh.tpl

This file was deleted.

0 comments on commit e90cd1a

Please sign in to comment.