Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19d2632

Browse files
committed
do not overwrite unconditionally
1 parent 77bfaff commit 19d2632

File tree

3 files changed

+186
-9
lines changed

3 files changed

+186
-9
lines changed

‎ci/semantic-line-breaks/Cargo.lock

Lines changed: 162 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ci/semantic-line-breaks/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ ignore = "0.4"
1010
[dependencies.regex]
1111
version = "1"
1212
features = ["pattern"]
13+
14+
[dependencies.clap]
15+
version = "4"
16+
features = ["derive"]

‎ci/semantic-line-breaks/src/main.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
use std::{env,fs, process};
1+
use std::{fs, path::PathBuf};
22

33
use anyhow::Result;
4+
use clap::Parser;
45
use ignore::Walk;
56
use regex::Regex;
67

8+
#[derive(Parser)]
9+
struct Cli {
10+
root_dir: PathBuf,
11+
#[arg(long)]
12+
overwrite: bool,
13+
}
14+
715
fn main() -> Result<()> {
8-
let mut args = env::args();
9-
if args.len() == 1 {
10-
eprintln!("error: expected root Markdown directory as CLI argument");
11-
process::exit(1);
12-
}
13-
let root_dir = args.nth(1).unwrap();
14-
for result in Walk::new(root_dir) {
16+
let cli = Cli::parse();
17+
for result in Walk::new(cli.root_dir) {
1518
let entry = result?;
1619
if entry.file_type().expect("no stdin").is_dir() {
1720
continue;
@@ -27,7 +30,15 @@ fn main() -> Result<()> {
2730
let old = fs::read_to_string(path)?;
2831
let new = comply(&old)?;
2932
if new != old {
30-
fs::write(path, new)?;
33+
if cli.overwrite {
34+
fs::write(path, new)?;
35+
} else {
36+
println!("{}:", path.display());
37+
println!("{new}");
38+
println!();
39+
println!("---");
40+
println!();
41+
}
3142
}
3243
}
3344
Ok(())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /