File: main.rs

package info (click to toggle)
rust-difference 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 312 kB
  • sloc: makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,094 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#![deny(warnings)]

#[cfg(feature = "bin")]
extern crate difference;
#[cfg(feature = "bin")]
extern crate getopts;

#[cfg(feature = "bin")]
use getopts::Options;
#[cfg(feature = "bin")]
use std::env;

#[cfg(not(feature = "bin"))]
fn main() {
    panic!("Needs to be compiled with --features=bin");
}

#[cfg(feature = "bin")]
fn main() {
    let args: Vec<String> = env::args().collect();
    let program = args[0].clone();

    let mut opts = Options::new();
    opts.optopt("s", "split", "", "char|word|line");
    let matches = match opts.parse(&args[1..]) {
        Ok(m) => m,
        Err(f) => panic!(f.to_string()),
    };

    let split = match matches.opt_str("s") {
        Some(ref x) if x == "char" => "",
        Some(ref x) if x == "word" => " ",
        Some(ref x) if x == "line" => "\n",
        _ => " ",
    };

    if matches.free.len() > 1 {
        let ch = difference::Changeset::new(&matches.free[0], &matches.free[1], split);
        println!("{}", ch);
    } else {
        print!("{}", opts.usage(&format!("Usage: {} [options]", program)));
        return;
    };


}