Skip to content

Commit ded9a75

Browse files
committed
Refactor viz app lib to allow subcommands
1 parent 0f2781f commit ded9a75

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

viz-udp-app/src/main.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use anyhow::anyhow;
22
use caw_viz_udp_app_lib::VizUdpClient;
3-
use clap::Parser;
3+
use clap::{Parser, Subcommand};
44
use line_2d::Coord;
55
use sdl2::{event::Event, pixels::Color, rect::Rect};
66
use std::collections::VecDeque;
77

88
#[derive(Parser)]
9-
struct Args {
10-
#[arg(long)]
11-
server: String,
9+
struct OscilloscopeCommand {
1210
#[arg(long, default_value_t = 640)]
1311
width: u32,
1412
#[arg(long, default_value_t = 480)]
@@ -29,13 +27,31 @@ struct Args {
2927
blue: u8,
3028
}
3129

30+
#[derive(Subcommand)]
31+
enum Command {
32+
Oscilloscope(OscilloscopeCommand),
33+
}
34+
35+
#[derive(Parser)]
36+
#[command(name = "caw_viz_udp_app")]
37+
#[command(
38+
about = "App for launching visualization for a caw synthesizer that receives data to visualize over udp"
39+
)]
40+
struct Cli {
41+
#[command(subcommand)]
42+
command: Command,
43+
#[arg(long)]
44+
server: String,
45+
}
46+
3247
#[derive(Default)]
3348
struct ScopeState {
3449
samples: VecDeque<(f32, f32)>,
3550
}
3651

3752
fn main() -> anyhow::Result<()> {
38-
let mut args = Args::parse();
53+
let Cli { server, command } = Cli::parse();
54+
let Command::Oscilloscope(mut args) = command;
3955
let sdl_context = sdl2::init().map_err(|e| anyhow!(e))?;
4056
let video_subsystem = sdl_context.video().map_err(|e| anyhow!(e))?;
4157
let window = video_subsystem
@@ -49,7 +65,7 @@ fn main() -> anyhow::Result<()> {
4965
.build()?;
5066
canvas.set_blend_mode(sdl2::render::BlendMode::Blend);
5167
let mut event_pump = sdl_context.event_pump().map_err(|e| anyhow!(e))?;
52-
let mut viz_udp_client = VizUdpClient::new(args.server)?;
68+
let mut viz_udp_client = VizUdpClient::new(server)?;
5369
let mut scope_state = ScopeState::default();
5470
loop {
5571
for event in event_pump.poll_iter() {

0 commit comments

Comments
 (0)