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(cli): command clean #2528

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions .changeset/new_clean_command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
@biomejs/biome: minor
---

# New `clean` command

Use this new command to clean after the `biome-logs` directory, and remove all the log files.

```shell
biome clean
```
10 changes: 10 additions & 0 deletions crates/biome_cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub use crate::commands::daemon::biome_log_dir;
ematipico marked this conversation as resolved.
Show resolved Hide resolved
use crate::{CliDiagnostic, CliSession};
use std::fs::{create_dir, remove_dir_all};

/// Runs the clean command
pub fn clean(_cli_session: CliSession) -> Result<(), CliDiagnostic> {
let logs_dir = biome_log_dir();
remove_dir_all(logs_dir.clone()).and_then(|_| create_dir(logs_dir))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we immediately recreate the dir? Wouldn't it be automatically recreated the next time you run biome anyway? If so, it feels "cleaner" to just remove and leave it at that...

Copy link
Member Author

Choose a reason for hiding this comment

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

If there's a Daemon running, it won't log anything anymore, and users would need to restart it manually to recreate the folder

Ok(())
}
6 changes: 6 additions & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::path::PathBuf;

pub(crate) mod check;
pub(crate) mod ci;
pub(crate) mod clean;
pub(crate) mod daemon;
pub(crate) mod explain;
pub(crate) mod format;
Expand Down Expand Up @@ -346,6 +347,10 @@ pub enum BiomeCommand {
doc: Doc,
},

#[bpaf(command)]
/// Clean the logs emitted by the daemon
Clean,

#[bpaf(command("__run_server"), hide)]
RunServer {
#[bpaf(long("stop-on-disconnect"), hide_usage)]
Expand Down Expand Up @@ -399,6 +404,7 @@ impl BiomeCommand {
| BiomeCommand::Init(_)
| BiomeCommand::Explain { .. }
| BiomeCommand::RunServer { .. }
| BiomeCommand::Clean { .. }
| BiomeCommand::PrintSocket => None,
}
}
Expand Down
9 changes: 1 addition & 8 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,9 @@ impl Display for RunningRomeServer {
")
.fmt(f)?;

// Version 10.0.0 and below did not include a service version in the pipe name
let version = if version.is_empty() {
"<=10.0.0"
} else {
version.as_str()
};

markup!(
{Section("Server")}
{KeyValuePair("Version", markup!({version}))}
{KeyValuePair("Version", markup!({version.as_str()}))}
)
.fmt(f)?;
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<'app> CliSession<'app> {
BiomeCommand::Rage(_, daemon_logs, formatter, linter) => {
commands::rage::rage(self, daemon_logs, formatter, linter)
}
BiomeCommand::Clean => commands::clean::clean(self),
BiomeCommand::Start(config_path) => commands::daemon::start(self, config_path),
BiomeCommand::Stop => commands::daemon::stop(self),
BiomeCommand::Check {
Expand Down