usbrh 0.1.0

A small tool and library for the USBRH (USB-connected temperature and humidity sensor). The USBRH uses Sensirion SHT11 sensor.
Documentation
extern crate simple_logger;
extern crate usbrh;
#[macro_use]
extern crate structopt;

use structopt::StructOpt;
use usbrh::read_sensors;

/// USBRH temperature and humidity reader
#[derive(StructOpt, Debug)]
#[structopt(name = "usbrh", author = "")]
struct Opt {
    // The number of occurrences of the `v/verbose` flag
    /// Verbose mode (-v, -vv, -vvv, etc.)
    #[structopt(short = "v", long = "verbose", parse(from_occurrences))]
    verbose: u32,

    /// Shows temperature
    #[structopt(short = "t", long = "temperature")]
    temperature: bool,

    /// Shows humidity
    #[structopt(short = "h", long = "humidity")]
    humidity: bool,

    /// Doesn't print the header
    #[structopt(short = "H", long = "no-header")]
    no_header: bool,

    /// Sets target device number
    #[structopt(short = "d", long = "device", default_value = "1")]
    device_num: u32,
}

fn main() {
    let opt = Opt::from_args();
    let opt = if !(opt.temperature || opt.humidity) {
        Opt {
            temperature: true,
            humidity: true,
            ..opt
        }
    } else {
        opt
    };
    if opt.verbose >= 1 {
        simple_logger::init().unwrap();
    }

    match read_sensors(opt.verbose, opt.device_num) {
        Ok(result) => {
            if opt.temperature && opt.humidity {
                if !opt.no_header {
                    println!("temperature\thumidity");
                }
                println!("{:.2}\t{:.2}", result.temperature, result.humidity);
            } else if opt.temperature {
                println!("{:.2}", result.temperature);
            } else if opt.humidity {
                println!("{:.2}", result.humidity);
            }
        }
        Err(e) => panic!("{}", e),
    }
}