example/
example.rs

1extern crate partition_identity;
2
3use partition_identity::{PartitionID, PartitionIdentifiers};
4use std::env;
5use std::process::exit;
6
7fn main() {
8    let mut args = env::args().skip(1);
9    match args.next() {
10        Some(arg) => match arg.as_str() {
11            "from-path" => {
12                let mut first = true;
13                for device in args {
14                    if !first {
15                        println!()
16                    }
17                    first = false;
18                    println!("{}:", device);
19                    println!("{:#?}", PartitionIdentifiers::from_path(device));
20                }
21            }
22            "by-id" => {
23                for id in args {
24                    let var = PartitionID::new_id(id.clone());
25                    println!("{}: {:?}", id, var.get_device_path());
26                }
27            }
28            "by-uuid" => {
29                for id in args {
30                    let var = PartitionID::new_uuid(id.clone());
31                    println!("{}: {:?}", id, var.get_device_path());
32                }
33            }
34            "by-partuuid" => {
35                for id in args {
36                    let var = PartitionID::new_partuuid(id.clone());
37                    println!("{}: {:?}", id, var.get_device_path());
38                }
39            }
40            "detect-by" => {
41                for id in args {
42                    let id = match PartitionID::from_disk_by_path(&id) {
43                        Ok(id) => id,
44                        Err(why) => {
45                            eprintln!("{}: {}", id, why);
46                            exit(1);
47                        }
48                    };
49
50                    println!("{:?} = {:?}", id, id.get_device_path());
51                }
52            }
53            _ => {
54                eprintln!(
55                    "invalid subcommand: valid commansd: [from-path, by-uuid, by-partuuid, ]"
56                );
57                exit(1);
58            }
59        },
60        None => {
61            eprintln!("must give subcommand: [from-path, by-uuid, by-partuuid, ]");
62            exit(1);
63        }
64    }
65}