blob: b5994e92cd1953f7be0e3ee27f8aee0da51043b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
fn main() {
if std::env::args().len() != 2 {
eprintln!("usage: popline <file>\n");
eprintln!("removes the first line of a file and rewrites it to disk without that line");
std::process::exit(1);
}
let file = std::path::PathBuf::from(std::env::args().nth(1).unwrap());
let string = std::fs::read_to_string(&file).unwrap();
let mut lines = string.lines();
let line = match lines.next() {
None => {
std::process::exit(1);
}
Some(line) => line,
};
let write = lines.collect::<Vec<&str>>().join("\n");
std::fs::write(file, write).unwrap();
println!("{line}");
}
|