Skip to content

Commit

Permalink
Use arguments from cli file
Browse files Browse the repository at this point in the history
  • Loading branch information
jldeen committed Dec 15, 2021
1 parent 608373a commit 1d6ecd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
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"),
)
}
19 changes: 10 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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").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();;

let switch = matches.value_of("SWITCH").unwrap();
let brightness = matches.value_of("BRIGHTNESS").unwrap();
let temperature = matches.value_of("TEMPERATURE").unwrap();
println!("Value for switch: {}", switch);

let body = json!({
"numberOfLights":numberoflights,
Expand All @@ -32,6 +32,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 1d6ecd0

Please sign in to comment.