Skip to content

Commit f4d8c7b

Browse files
[Rust] Add a command for installing rules/rules.md into a repository (#17405)
1 parent 4e626d7 commit f4d8c7b

6 files changed

Lines changed: 668 additions & 1 deletion

File tree

rust/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ rust_library(
9191
["src/**/*.rs"],
9292
exclude = ["main.rs"],
9393
),
94-
compile_data = ["src/resources/skills.md"],
94+
compile_data = [
95+
"src/resources/rules.md",
96+
"src/resources/skills.md",
97+
],
9598
crate_features = select({
9699
"//common:stamp": [],
97100
"//conditions:default": ["avoid_stats"],
@@ -106,6 +109,7 @@ filegroup(
106109
srcs = [
107110
"Cargo.lock",
108111
"Cargo.toml",
112+
"src/resources/rules.md",
109113
"src/resources/skills.md",
110114
":selenium_manager_rs_srcs",
111115
],

rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub mod lock;
7070
pub mod logger;
7171
pub mod metadata;
7272
pub mod mirror;
73+
pub mod rules;
7374
pub mod safari;
7475
pub mod safaritp;
7576
pub mod shell;

rust/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use selenium_manager::jre::ensure_jre;
2727
use selenium_manager::lock::clear_lock_if_required;
2828
use selenium_manager::logger::{BROWSER_PATH, DRIVER_PATH, Logger};
2929
use selenium_manager::metadata::clear_metadata;
30+
use selenium_manager::rules::write_rules_file;
3031
use selenium_manager::skills::write_skills_file;
3132
use selenium_manager::{REQUEST_TIMEOUT_SEC, SM_BETA_LABEL};
3233
use selenium_manager::{
@@ -162,6 +163,10 @@ struct Cli {
162163
/// Add a skills file with Selenium best practices to the repository
163164
#[clap(long, value_name = "FILE_NAME", num_args = 0..=1, default_missing_value = "")]
164165
init_skills: Option<String>,
166+
167+
/// Add a rules file with Selenium guidance for LLM coding assistants to the repository
168+
#[clap(long, value_name = "FILE_NAME", num_args = 0..=1, default_missing_value = "")]
169+
init_rules: Option<String>,
165170
}
166171

167172
fn main() {
@@ -189,6 +194,23 @@ fn main() {
189194
flush_and_exit(OK, &log, None);
190195
}
191196

197+
if let Some(mut rules_file) = cli.init_rules {
198+
if rules_file.is_empty() {
199+
let default_path = Path::new("rules").join("selenium.md");
200+
if default_path.exists() {
201+
rules_file = "selenium-rules.md".to_string();
202+
} else {
203+
rules_file = default_path.to_string_lossy().to_string();
204+
}
205+
}
206+
if let Err(err) = write_rules_file(Path::new(&rules_file), &log) {
207+
log.error(format!("Error creating {}: {}", rules_file, err));
208+
flush_and_exit(DATAERR, &log, Some(err));
209+
}
210+
log.info(format!("{} file successfully created", rules_file));
211+
flush_and_exit(OK, &log, None);
212+
}
213+
192214
let cache_path =
193215
StringKey(vec![CACHE_PATH_KEY], &cli.cache_path.unwrap_or_default()).get_value();
194216
let grid = cli.grid;

0 commit comments

Comments
 (0)