summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: c4db10df6f36aca32574b9d6ec5116d73559c1d6 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
//!
//! Simple command line tool to analyse disk usage from the terminal
//!
//! # Usage
//!
//! ```text
//! $ dutree --help
//! Usage: dutree [options] <path> [<path>..]
//!
//! Options:
//!     -d, --depth [DEPTH] show directories up to depth N (def 1)
//!     -a, --aggr [N[KMG]] aggregate smaller than N B/KiB/MiB/GiB (def 1M)
//!     -s, --summary       equivalent to -da, or -d1 -a1M
//!     -u, --usage         report real disk usage instead of file size
//!     -b, --bytes         print sizes in bytes
//!     -x, --exclude NAME  exclude matching files or directories
//!     -H, --no-hidden     exclude hidden files
//!     -A, --ascii         ASCII characters only, no colors
//!     -h, --help          show help
//!     -v, --version       print version number
//! ```
//! # Screenshot
//!
//! ![dutree](https://ownyourbits.com/wp-content/uploads/2018/03/dutree-featured2.png)
//!
//! # More information
//!
//! Copyleft 2018 by Ignacio Nunez Hernanz - nacho _at_ ownyourbits _dot_ com
//!
//! GPL licensed
//!
//! More at [ownyourbits.com](https://ownyourbits.com/2018/03/25/analize-disk-usage-with-dutree)
//!
//! [github](https://github.com/nachoparker/dutree)
//!

extern crate dutree;

use dutree::Config;
use dutree::XResult::XErr;
use dutree::XResult::XOk;
use dutree::XResult::XExit;
use std::process;

fn main() {

    // handle SIGPIPE
    let _signal = unsafe { signal_hook::register(signal_hook::SIGPIPE, || process::exit(0)) };

    // Parse arguments
    let cfg = match Config::new() {
        XOk(cfg)  => cfg,
        XExit     => process::exit(0),
        XErr(err) => {
            eprintln!( "{}", err );
            process::exit(1)
        }
    };

    // Execution
    dutree::run( &cfg );
}

// License
//
// This script is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This script is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this script; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330,