Switched the command line arguments around and added LUX_DEVICE environment variable.

This commit is contained in:
Simon Johnston 2020-08-17 16:22:21 -07:00
parent 6b8aa07adc
commit 6b5fb893ef
3 changed files with 21 additions and 29 deletions

View File

@ -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. The following shows the command line tool setting the color to red.
```bash ```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 ```bash
lux blink green -d 2a0f2c73b72 export LUX_DEVICE=2a0f2c73b72
lux blink green
``` ```
The following shows the command line tool turning the light off. The following shows the command line tool turning the light off.
```bash ```bash
lux -vvv off -d 2a0f2c73b72 lux -vvv -d 2a0f2c73b72 off
INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000 INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000
INFO luxafor > call successful INFO luxafor > call successful
``` ```

View File

@ -12,6 +12,10 @@ pub(crate) struct CommandLine {
#[structopt(long, short = "v", parse(from_occurrences))] #[structopt(long, short = "v", parse(from_occurrences))]
verbose: i8, verbose: i8,
/// The device identifier
#[structopt(long, short, env = "LUX_DEVICE")]
device: DeviceID,
#[structopt(subcommand)] #[structopt(subcommand)]
cmd: SubCommand, cmd: SubCommand,
} }
@ -20,40 +24,24 @@ pub(crate) struct CommandLine {
pub(crate) enum SubCommand { pub(crate) enum SubCommand {
/// Set the light to a to a solid color /// Set the light to a to a solid color
Solid { Solid {
/// The device identifier
#[structopt(long, short)]
device: DeviceID,
/// The color to set /// The color to set
#[structopt(name = "COLOR")] #[structopt(name = "COLOR")]
color: SolidColor, color: SolidColor,
}, },
/// Set the light to a to a blinking color /// Set the light to a to a blinking color
Blink { Blink {
/// The device identifier
#[structopt(long, short)]
device: DeviceID,
/// The color to set /// The color to set
#[structopt(name = "COLOR")] #[structopt(name = "COLOR")]
color: SolidColor, color: SolidColor,
}, },
/// Set the light to a to a pre-defined pattern /// Set the light to a to a pre-defined pattern
Pattern { Pattern {
/// The device identifier
#[structopt(long, short)]
device: DeviceID,
/// The pattern to set /// The pattern to set
#[structopt(long, short)] #[structopt(long, short)]
pattern: Pattern, pattern: Pattern,
}, },
/// Turn the light off /// Turn the light off
Off { Off,
/// The device identifier
#[structopt(long, short)]
device: DeviceID,
},
} }
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
@ -71,10 +59,10 @@ fn main() -> Result<(), Box<dyn Error>> {
.init(); .init();
match args.cmd { match args.cmd {
SubCommand::Solid { device, color } => set_solid_color(device, color, false), SubCommand::Solid { color } => set_solid_color(args.device, color, false),
SubCommand::Blink { device, color } => set_solid_color(device, color, true), SubCommand::Blink { color } => set_solid_color(args.device, color, true),
SubCommand::Pattern { device, pattern } => set_pattern(device, pattern), SubCommand::Pattern { pattern } => set_pattern(args.device, pattern),
SubCommand::Off { device } => turn_off(device), SubCommand::Off => turn_off(args.device),
}?; }?;
Ok(()) Ok(())

View File

@ -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. The following shows the command line tool setting the color to red.
```bash ```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 ```bash
lux blink green -d 2a0f2c73b72 export LUX_DEVICE=2a0f2c73b72
lux blink green
``` ```
The following shows the command line tool turning the light off. The following shows the command line tool turning the light off.
```bash ```bash
lux -vvv off -d 2a0f2c73b72 lux -vvv -d 2a0f2c73b72 off
INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000 INFO luxafor > Setting the color of device '2a0f2c73b72e' to 000000
INFO luxafor > call successful INFO luxafor > call successful
``` ```