example/
example.rs

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
extern crate partition_identity;

use partition_identity::{PartitionID, PartitionIdentifiers};
use std::env;
use std::process::exit;

fn main() {
    let mut args = env::args().skip(1);
    match args.next() {
        Some(arg) => match arg.as_str() {
            "from-path" => {
                let mut first = true;
                for device in args {
                    if !first {
                        println!()
                    }
                    first = false;
                    println!("{}:", device);
                    println!("{:#?}", PartitionIdentifiers::from_path(device));
                }
            }
            "by-id" => {
                for id in args {
                    let var = PartitionID::new_id(id.clone());
                    println!("{}: {:?}", id, var.get_device_path());
                }
            }
            "by-uuid" => {
                for id in args {
                    let var = PartitionID::new_uuid(id.clone());
                    println!("{}: {:?}", id, var.get_device_path());
                }
            }
            "by-partuuid" => {
                for id in args {
                    let var = PartitionID::new_partuuid(id.clone());
                    println!("{}: {:?}", id, var.get_device_path());
                }
            }
            "detect-by" => {
                for id in args {
                    let id = match PartitionID::from_disk_by_path(&id) {
                        Ok(id) => id,
                        Err(why) => {
                            eprintln!("{}: {}", id, why);
                            exit(1);
                        }
                    };

                    println!("{:?} = {:?}", id, id.get_device_path());
                }
            }
            _ => {
                eprintln!(
                    "invalid subcommand: valid commansd: [from-path, by-uuid, by-partuuid, ]"
                );
                exit(1);
            }
        },
        None => {
            eprintln!("must give subcommand: [from-path, by-uuid, by-partuuid, ]");
            exit(1);
        }
    }
}