Switched the command line arguments around and added LUX_DEVICE
environment variable.
This commit is contained in:
parent
6b8aa07adc
commit
6b5fb893ef
10
README.md
10
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
|
||||
```
|
||||
|
@ -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<dyn Error>> {
|
||||
@ -71,10 +59,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.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(())
|
||||
|
10
src/lib.rs
10
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
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user