Skip to content

Commit 5a93a2a

Browse files
committed
feat: enhance cli
1 parent 8dfbb4b commit 5a93a2a

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,4 @@ pub enum RustmotionError {
174174
// --- Preview ---
175175
#[error("Failed to create preview window: {reason}")]
176176
PreviewWindow { reason: String },
177-
178-
#[error("--preview requires an input file path (cannot use --json or stdin)")]
179-
PreviewRequiresFile,
180177
}

src/main.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,18 @@ struct Cli {
3838

3939
#[derive(Subcommand)]
4040
enum Commands {
41-
/// Render a JSON scenario to MP4
41+
/// Open a live preview window with hot-reload
42+
Studio {
43+
/// Path to the JSON scenario file
44+
#[arg(short, long)]
45+
file: PathBuf,
46+
},
47+
48+
/// Render a JSON scenario to video or a single frame
4249
Render {
4350
/// Path to the JSON scenario file
44-
input: Option<PathBuf>,
51+
#[arg(short, long)]
52+
file: Option<PathBuf>,
4553

4654
/// Inline JSON scenario string
4755
#[arg(long)]
@@ -78,16 +86,13 @@ enum Commands {
7886
/// Watch the input file for changes and re-render automatically
7987
#[arg(short, long)]
8088
watch: bool,
81-
82-
/// Open a preview window instead of encoding
83-
#[arg(short = 'p', long)]
84-
preview: bool,
8589
},
8690

8791
/// Export a single frame as a still image (PNG, JPEG, WebP)
8892
Still {
8993
/// Path to the JSON scenario file
90-
input: PathBuf,
94+
#[arg(short, long)]
95+
file: PathBuf,
9196

9297
/// Output file path
9398
#[arg(short, long, default_value = "still.png")]
@@ -109,7 +114,8 @@ enum Commands {
109114
/// Validate a JSON scenario without rendering
110115
Validate {
111116
/// Path to the JSON scenario file
112-
input: PathBuf,
117+
#[arg(short, long)]
118+
file: PathBuf,
113119
},
114120

115121
/// Print the JSON Schema for scenario files
@@ -122,7 +128,8 @@ enum Commands {
122128
/// Show information about a scenario
123129
Info {
124130
/// Path to the JSON scenario file
125-
input: PathBuf,
131+
#[arg(short, long)]
132+
file: PathBuf,
126133
},
127134
}
128135

@@ -143,8 +150,12 @@ fn main() -> Result<()> {
143150
}
144151

145152
match cli.command {
153+
Commands::Studio { file } => {
154+
let scenario = load_scenario(&file)?;
155+
preview::run_preview(scenario, Some(file), true)
156+
}
146157
Commands::Render {
147-
input,
158+
file,
148159
json,
149160
output,
150161
frame,
@@ -154,27 +165,22 @@ fn main() -> Result<()> {
154165
format,
155166
transparent,
156167
watch,
157-
preview,
158168
} => {
159-
if preview {
160-
let input_path = input.ok_or(RustmotionError::PreviewRequiresFile)?;
161-
let scenario = load_scenario(&input_path)?;
162-
preview::run_preview(scenario, Some(input_path), watch)
163-
} else if watch {
164-
let input_path = input.ok_or(RustmotionError::WatchRequiresFile)?;
169+
if watch {
170+
let input_path = file.ok_or(RustmotionError::WatchRequiresFile)?;
165171
cmd_watch(&input_path, &output, frame, output_format.as_ref(), cli.quiet, codec, crf, format, transparent)
166172
} else {
167-
let scenario = load_scenario_from_source(input.as_ref(), json.as_deref())?;
173+
let scenario = load_scenario_from_source(file.as_ref(), json.as_deref())?;
168174
cmd_render(scenario, &output, frame, output_format.as_ref(), cli.quiet, codec, crf, format, transparent)
169175
}
170176
}
171-
Commands::Still { input, output, time, format, quality } => {
172-
let scenario = load_scenario(&input)?;
177+
Commands::Still { file, output, time, format, quality } => {
178+
let scenario = load_scenario(&file)?;
173179
cmd_still(scenario, &output, time, format, quality)
174180
}
175-
Commands::Validate { input } => cmd_validate(&input),
181+
Commands::Validate { file } => cmd_validate(&file),
176182
Commands::Schema { output } => cmd_schema(output.as_deref()),
177-
Commands::Info { input } => cmd_info(&input),
183+
Commands::Info { file } => cmd_info(&file),
178184
}
179185
}
180186

src/preview.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ impl PreviewApp {
337337
}
338338
self.request_frame(self.current_frame);
339339
}
340+
// Force redraw so the play/pause icon updates immediately
341+
if let Some(window) = &self.window {
342+
window.request_redraw();
343+
}
340344
self.update_title();
341345
}
342346

0 commit comments

Comments
 (0)