~iptq/garbage

ref: 02ba29053be29149ec4ca4f73cd375f02f2cf21b garbage/src/main.rs -rw-r--r-- 1.4 KiB
02ba2905Michael Zhang fix panic problem by not converting to utf-8 all the time 1 year, 5 months ago
                                                                                
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
#![deny(warnings)]

extern crate anyhow;

use anyhow::Result;
use garbage::ops::{self, EmptyOptions, ListOptions, PutOptions, RestoreOptions};
use structopt::StructOpt;

#[derive(StructOpt)]
enum Command {
    /// Empty a trash directory.
    #[structopt(name = "empty")]
    Empty(EmptyOptions),

    /// List the contents of a trash directory.
    #[structopt(name = "list")]
    List(ListOptions),

    /// Puts files into the trash.
    ///
    /// If a trash directory isn't specified, the best strategy is picked
    /// for each file that's deleted (after shell glob expansion). The algorithm
    /// for deciding a strategy is specified in the FreeDesktop Trash spec.
    #[structopt(name = "put")]
    Put(PutOptions),

    /// Restores files from the trash.
    #[structopt(name = "restore")]
    Restore(RestoreOptions),
}

fn run() -> Result<()> {
    let cmd = Command::from_args();
    match cmd {
        Command::Empty(options) => ops::empty(options),
        Command::List(options) => ops::list(options),
        Command::Put(options) => ops::put(options),
        Command::Restore(options) => ops::restore(options),
    }
}

fn main() {
    match run() {
        Ok(_) => (),
        Err(err) => {
            eprintln!("Error: {:?}", err);
            // for cause in err.chain() {
            //     eprintln!("- {:?}", cause);
            // }
        }
    }
}