Skip to content

Commit 934c627

Browse files
committed
As the default works
1 parent cd9396e commit 934c627

File tree

1 file changed

+67
-23
lines changed

1 file changed

+67
-23
lines changed

src/cmd/submit.rs

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,40 @@ impl App {
233233
}
234234

235235
pub fn initialize_with_directives(&mut self, popcorn_directives: utils::PopcornDirectives) {
236-
if !popcorn_directives.leaderboard_name.is_empty() {
237-
self.selected_leaderboard = Some(popcorn_directives.leaderboard_name);
236+
let has_leaderboard = !popcorn_directives.leaderboard_name.is_empty();
237+
let has_gpu = !popcorn_directives.gpus.is_empty();
238238

239-
if !popcorn_directives.gpus.is_empty() {
240-
self.selected_gpu = Some(popcorn_directives.gpus[0].clone());
239+
// Set the selected values from directives
240+
if has_leaderboard {
241+
self.selected_leaderboard = Some(popcorn_directives.leaderboard_name.clone());
242+
}
243+
if has_gpu {
244+
self.selected_gpu = Some(popcorn_directives.gpus[0].clone());
245+
}
246+
247+
// Determine initial state based on what's available
248+
match (has_leaderboard, has_gpu) {
249+
(true, true) => {
250+
// Both leaderboard and GPU specified - go directly to submission mode selection
241251
self.app_state = AppState::SubmissionModeSelection;
242-
} else {
252+
self.submission_mode_view = Some(SubmissionModeSelectionView::new(
253+
self.submission_modes.clone(),
254+
popcorn_directives.leaderboard_name,
255+
popcorn_directives.gpus[0].clone(),
256+
));
257+
}
258+
(true, false) => {
259+
// Only leaderboard specified - need to select GPU
243260
self.app_state = AppState::GpuSelection;
244261
}
245-
} else if !popcorn_directives.gpus.is_empty() {
246-
self.selected_gpu = Some(popcorn_directives.gpus[0].clone());
247-
if !popcorn_directives.leaderboard_name.is_empty() {
248-
self.selected_leaderboard = Some(popcorn_directives.leaderboard_name);
249-
self.app_state = AppState::SubmissionModeSelection;
250-
} else {
262+
(false, true) => {
263+
// Only GPU specified - need to select leaderboard
264+
self.app_state = AppState::LeaderboardSelection;
265+
}
266+
(false, false) => {
267+
// Neither specified - start from leaderboard selection
251268
self.app_state = AppState::LeaderboardSelection;
252269
}
253-
} else {
254-
self.app_state = AppState::LeaderboardSelection;
255270
}
256271
}
257272

@@ -290,10 +305,41 @@ impl App {
290305
if let Some(view) = &mut self.file_selection_view {
291306
match view.handle_key_event(key)? {
292307
FileSelectionAction::FileSelected(filepath) => {
293-
self.filepath = filepath;
294-
self.app_state = AppState::LeaderboardSelection;
295-
if let Err(e) = self.spawn_load_leaderboards() {
296-
self.show_error(format!("Error starting leaderboard fetch: {}", e));
308+
self.filepath = filepath.clone();
309+
310+
// Parse directives from the selected file
311+
match utils::get_popcorn_directives(&filepath) {
312+
Ok((directives, has_multiple_gpus)) => {
313+
if has_multiple_gpus {
314+
self.show_error("Multiple GPUs are not supported yet. Please specify only one GPU.".to_string());
315+
return Ok(true);
316+
}
317+
318+
// Apply directives to determine next state
319+
self.initialize_with_directives(directives);
320+
321+
// Spawn appropriate task based on the new state
322+
match self.app_state {
323+
AppState::LeaderboardSelection => {
324+
if let Err(e) = self.spawn_load_leaderboards() {
325+
self.show_error(format!("Error starting leaderboard fetch: {}", e));
326+
}
327+
}
328+
AppState::GpuSelection => {
329+
if let Err(e) = self.spawn_load_gpus() {
330+
self.show_error(format!("Error starting GPU fetch: {}", e));
331+
}
332+
}
333+
AppState::SubmissionModeSelection => {
334+
// View already created in initialize_with_directives
335+
}
336+
_ => {}
337+
}
338+
}
339+
Err(e) => {
340+
self.show_error(format!("Error parsing file directives: {}", e));
341+
return Ok(true);
342+
}
297343
}
298344
return Ok(true);
299345
}
@@ -642,7 +688,10 @@ pub async fn run_submit_tui(
642688
));
643689
}
644690

645-
// Override directives with CLI flags if provided
691+
// First apply directives as defaults
692+
app.initialize_with_directives(directives);
693+
694+
// Then override with CLI flags if provided
646695
if let Some(gpu_flag) = gpu {
647696
app.selected_gpu = Some(gpu_flag);
648697
}
@@ -657,11 +706,6 @@ pub async fn run_submit_tui(
657706
}
658707
}
659708

660-
// If no CLI flags, use directives
661-
if app.selected_gpu.is_none() && app.selected_leaderboard.is_none() {
662-
app.initialize_with_directives(directives);
663-
}
664-
665709
// Spawn the initial task based on the starting state BEFORE setting up the TUI
666710
match app.app_state {
667711
AppState::LeaderboardSelection => {

0 commit comments

Comments
 (0)