diff --git a/README.md b/README.md index 4ca4498..8b3d4c2 100644 --- a/README.md +++ b/README.md @@ -17,19 +17,21 @@ as well as the [Bluetooth](https://luxafor.com/bluetooth-busy-light-availability The following shows the command line tool setting the color to red. ```bash -❯ lux solid red -d 2a0f2c73b72 +❯ lux -d 2a0f2c73b72 solid red ``` -The following shows the command line tool setting the color to a blinking green. +The following shows the command line tool setting the color to a blinking green. This example uses the environment +variable `LUX_DEVICE` to save repeating the device identifier on each call. ```bash -❯ lux blink green -d 2a0f2c73b72 +❯ export LUX_DEVICE=2a0f2c73b72 +❯ lux blink green ``` The following shows the command line tool turning the light off. ```bash -❯ lux -vvv off -d 2a0f2c73b72 +❯ lux -vvv -d 2a0f2c73b72 off INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000 INFO luxafor > call successful ``` diff --git a/src/bin/main.rs b/src/bin/main.rs index 7fcbd49..016aec6 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -12,6 +12,10 @@ pub(crate) struct CommandLine { #[structopt(long, short = "v", parse(from_occurrences))] verbose: i8, + /// The device identifier + #[structopt(long, short, env = "LUX_DEVICE")] + device: DeviceID, + #[structopt(subcommand)] cmd: SubCommand, } @@ -20,40 +24,24 @@ pub(crate) struct CommandLine { pub(crate) enum SubCommand { /// Set the light to a to a solid color Solid { - /// The device identifier - #[structopt(long, short)] - device: DeviceID, - /// The color to set #[structopt(name = "COLOR")] color: SolidColor, }, /// Set the light to a to a blinking color Blink { - /// The device identifier - #[structopt(long, short)] - device: DeviceID, - /// The color to set #[structopt(name = "COLOR")] color: SolidColor, }, /// Set the light to a to a pre-defined pattern Pattern { - /// The device identifier - #[structopt(long, short)] - device: DeviceID, - /// The pattern to set #[structopt(long, short)] pattern: Pattern, }, /// Turn the light off - Off { - /// The device identifier - #[structopt(long, short)] - device: DeviceID, - }, + Off, } fn main() -> Result<(), Box> { @@ -71,10 +59,10 @@ fn main() -> Result<(), Box> { .init(); match args.cmd { - SubCommand::Solid { device, color } => set_solid_color(device, color, false), - SubCommand::Blink { device, color } => set_solid_color(device, color, true), - SubCommand::Pattern { device, pattern } => set_pattern(device, pattern), - SubCommand::Off { device } => turn_off(device), + SubCommand::Solid { color } => set_solid_color(args.device, color, false), + SubCommand::Blink { color } => set_solid_color(args.device, color, true), + SubCommand::Pattern { pattern } => set_pattern(args.device, pattern), + SubCommand::Off => turn_off(args.device), }?; Ok(()) diff --git a/src/lib.rs b/src/lib.rs index 8af06cd..99d696f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,19 +8,21 @@ as well as the [Bluetooth](https://luxafor.com/bluetooth-busy-light-availability The following shows the command line tool setting the color to red. ```bash -❯ lux solid red -d 2a0f2c73b72 +❯ lux -d 2a0f2c73b72 solid red ``` -The following shows the command line tool setting the color to a blinking green. +The following shows the command line tool setting the color to a blinking green. This example uses the environment +variable `LUX_DEVICE` to save repeating the device identifier on each call. ```bash -❯ lux blink green -d 2a0f2c73b72 +❯ export LUX_DEVICE=2a0f2c73b72 +❯ lux blink green ``` The following shows the command line tool turning the light off. ```bash -❯ lux -vvv off -d 2a0f2c73b72 +❯ lux -vvv -d 2a0f2c73b72 off INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000 INFO luxafor > call successful ```