Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .zpkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[package]
org = "led-dynamo"
name = "leddy-cli"
version = "0.1.0"
description = "Command-line client for publishing, clearing, inspecting, and automating Leddy displays"
license = "MIT"
keywords = ["led-matrix", "cli", "automation", "iot", "rust"]
language = "rust"

[package.repository]
vcs = "git"
url = "https://github.com/led-dynamo/leddy-cli"

[dependencies]
"led-dynamo/leddy-interfaces" = "^0.1.0"
"led-dynamo/leddy-lib" = "^0.1.0"
"led-dynamo/leddy-clients" = "^0.1.0"

[build]
command = "cargo build --release"
outputs = ["target/release/leddy-cli"]

[bin]
leddy = "target/release/leddy-cli"

[publish]
include_readme = true
tag_format = "v{version}"
smoke_test = "test -x \"$ZED_PKG_TEST_TARGET/target/release/leddy-cli\" && \"$ZED_PKG_TEST_TARGET/target/release/leddy-cli\" --help"
exclude = [
".env",
".env.*",
".vendor/.zed/**",
".zed/**",
".zed-pack/**",
"target/**",
"**/*.log",
]

[publish.native]
registry = "crates-io"
package = "leddy-cli"

[install]
adapter = "none"
dir = ".vendor/.zed"

[scripts]
test = "cargo test --all-targets"
26 changes: 21 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = LeddyClient::new(arguments.api_url);

match arguments.command {
Command::Send { text, speed, direction } => {
Command::Send {
text,
speed,
direction,
} => {
let message = MessageEnvelope {
id: format!("cli-{}", now_unix_ms()),
text,
speed_pixels_per_second: speed,
direction: match direction { Direction::Left => ScrollDirection::Left, Direction::Right => ScrollDirection::Right },
direction: match direction {
Direction::Left => ScrollDirection::Left,
Direction::Right => ScrollDirection::Right,
},
repeat: RepeatMode::Forever,
issued_at_unix_ms: now_unix_ms(),
};
message.validate()?;
let width = leddy_lib::content_width(&message.text);
let status = client.publish_message(&message).await?;
println!("accepted {} ({} rendered pixels, HTTP {})", message.id, width, status);
println!(
"accepted {} ({} rendered pixels, HTTP {})",
message.id, width, status
);
}
Command::Clear => println!("clear accepted (HTTP {})", client.clear().await?),
Command::Health => { client.health().await?; println!("ok"); }
Command::Health => {
client.health().await?;
println!("ok");
}
}
Ok(())
}

fn now_unix_ms() -> u64 {
SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis() as u64
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64
}