mod lib;
#[macro_use]
extern crate clap;
extern crate serde_json;
use lib::*;
use std::env;
use serde_json::{json, value::Value};
fn main() {
dotenv::dotenv().ok();
let matches = clap_app!(myapp =>
(version: "0.1.0")
(author: "Art Eidukas <iwiivi@gmail.com>")
(about: "Given HUE bridge credentials, allows control over your HUE lights")
(@subcommand all =>
(about: "Sends commands to all lights")
(version: "0.1.0")
(@arg STATE: -s --state +takes_value "Takes a string input representing a new state to send to ALL lights")
)
)
.get_matches();
let mut bridge = Bridge::link();
if let Some(matches) = matches.subcommand_matches("all") {
if let Some(jsn) = matches.value_of("STATE") {
let parsed = serde_json::from_str::<Value>(jsn);
match parsed {
Ok(state) => {
bridge.state_all(&state);
}
Err(e) => println!("Error in parsing state: {}", e),
}
}
}
}