Skip to content

Commit

Permalink
Merge pull request #1 from jldeen/update-arguments-and-first-release
Browse files Browse the repository at this point in the history
Use arguments from cli file
  • Loading branch information
jldeen authored Dec 15, 2021
2 parents 608373a + ef2c6c5 commit d7027af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ clap = "*"
reqwest = { version = "*", features = ["json", "blocking"] }
serde = { version = "*", features = ["derive"] }
serde_json = "*"
structopt = "*"
tokio = { version = "*", features = ["macros"] }
45 changes: 24 additions & 21 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ pub fn get_app_cli<'a, 'b>(version: &'b str) -> App<'a, 'b> {
.version(&*version)
.author("Jessica Deen <jessica.deen@microsoft.com>")
.about("Easy CLI to control Elgato Keylight")
.arg(
Arg::with_name("switch")
.index(1)
.required(true)
.short("s")
.long("switch")
.takes_value(true)
.value_name("ON/OFF")
.help("Switch value for light status: Accepted values are: on, off."),
)
.arg(
Arg::with_name("brightness")
.help("Brightness value for light: Accepted values are: low, medium, high.")
.required(true)
.index(2)
.default_value("20"),
)
.arg(
Arg::with_name("temperature")
.help("Temperature value for light: Accepted values are: warm, medium, cool.")
.required(true)
.index(3)
.default_value("213"),
)
.arg(
Arg::with_name("ELGATO_IP")
.long("elgato-ip-address")
Expand All @@ -27,25 +51,4 @@ pub fn get_app_cli<'a, 'b>(version: &'b str) -> App<'a, 'b> {
.env("NUMBER_OF_LIGHTS")
.takes_value(true),
)
.arg(
Arg::with_name("SWITCH")
.help("Switch value for light status: Accepted values are: on, off.")
.required(true)
.index(1)
.default_value("off"),
)
.arg(
Arg::with_name("BRIGHTNESS")
.help("Brightness value for light: Accepted values are: low, medium, high.")
.required(true)
.index(2)
.default_value("medium"),
)
.arg(
Arg::with_name("TEMPERATURE")
.help("Temperature value for light: Accepted values are: warm, medium, cool.")
.required(true)
.index(3)
.default_value("medium"),
)
}
27 changes: 17 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@ mod cli;
use cli::get_app_cli;
use reqwest::Client;
use serde_json::json;
use std::env;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let version = format!(
"{}.{}",
env!("CARGO_PKG_VERSION"),
option_env!("BUILD_BUILDID").unwrap_or("0")
);
let version = format!("v{}", env!("CARGO_PKG_VERSION"));

let matches = get_app_cli(&version).get_matches();
let elgato_ip = matches.value_of("ELGATO_IP").unwrap();
let numberoflights = matches.value_of("NUMBER_OF_LIGHTS").unwrap();

let switch = matches.value_of("SWITCH").unwrap();
let brightness = matches.value_of("BRIGHTNESS").unwrap();
let temperature = matches.value_of("TEMPERATURE").unwrap();
let switch = matches
.value_of("switch")
.and_then(|s| s.parse::<u8>().ok())
.unwrap();
let brightness = matches
.value_of("brightness")
.and_then(|s| s.parse::<u8>().ok())
.unwrap();
let temperature = matches
.value_of("temperature")
.and_then(|s| s.parse::<u8>().ok())
.unwrap();

println!("Value for switch: {}", switch);

let body = json!({
"numberOfLights":numberoflights,
Expand All @@ -32,6 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
]
});

let url = format!("http://{}:{}", elgato_ip, "9123/elgato/lights");

println!("State: {}", url);
Expand Down

0 comments on commit d7027af

Please sign in to comment.