Commit c347aad699

c347aad6990cd02ff4f2414895d5301f9adaddb4

parent: 5a483c7846

Unsigned

Vaibhav Mattoo <vaibhavmattoo1@gmail.com> · 2025-08-16 03:06 UTC

fix: corrected usage indication for some loadpage commands

Layout: unified · split

src/global/functions/run_command.rs +64 −9
@@ -18,11 +18,9 @@ use tui_additions::framework::Framework;
1818
1919/// runs text command - command from the command line (not TUI) which response is just a string
2020pub fn text_command(command: &str) -> Option<String> {
21 match command
22 .split_ascii_whitespace()
23 .collect::<Vec<_>>()
24 .as_slice()
25 {
21 let command_parts: Vec<&str> = command.split_ascii_whitespace().collect();
22
23 match command_parts.as_slice() {
2624 ["help"] => Some(help_msg(
2725 &CommandsRemapConfig::load(WriteConfig::Dont).unwrap(),
2826 )),
@@ -31,7 +29,64 @@ pub fn text_command(command: &str) -> Option<String> {
3129 env!("CARGO_PKG_NAME"),
3230 env!("CARGO_PKG_VERSION")
3331 )),
34 _ => None,
32 ["loadpage", page, ..] => {
33 // Validate loadpage commands from command line to prevent hanging in raw screen
34 match *page {
35 "popular" | "trending" | "watchhistory" | "feed" | "library" => {
36 if command_parts.len() != 2 {
37 return Some(format!("Usage: `loadpage {}`", page));
38 }
39 None // Let it proceed to TUI
40 }
41 "channel" | "video" | "playlist" => {
42 if command_parts.len() != 3 {
43 return Some(format!("Usage: `loadpage {} {{id/url}}`", page));
44 }
45 None // Let it proceed to TUI
46 }
47 "search" => {
48 if command_parts.len() < 3 {
49 return Some("Usage: `loadpage search {query}`".to_string());
50 }
51 None // Let it proceed to TUI
52 }
53 _ => Some(format!("Unknown page: `{}`", page)),
54 }
55 }
56 _ => {
57 // Check if this is a remapped command that would become a loadpage command
58 if let Some(remapped_cmd) = CommandsRemapConfig::load(WriteConfig::Dont)
59 .unwrap()
60 .get(&command_parts)
61 {
62 // If it remaps to a loadpage command, validate it
63 if remapped_cmd.starts_with("loadpage ") {
64 let remapped_parts: Vec<&str> = remapped_cmd.split_ascii_whitespace().collect();
65 if remapped_parts.len() >= 2 {
66 let page = remapped_parts[1];
67 match page {
68 "popular" | "trending" | "watchhistory" | "feed" | "library" => {
69 if command_parts.len() != 1 {
70 return Some(format!("Usage: `{}`", command_parts[0]));
71 }
72 }
73 "channel" | "video" | "playlist" => {
74 if command_parts.len() != 2 {
75 return Some(format!("Usage: `{} {{id/url}}`", command_parts[0]));
76 }
77 }
78 "search" => {
79 if command_parts.len() < 2 {
80 return Some(format!("Usage: `{} {{query}}`", command_parts[0]));
81 }
82 }
83 _ => {}
84 }
85 }
86 }
87 }
88 None
89 }
3590 }
3691}
3792
@@ -127,7 +182,7 @@ pub fn run_single_command(
127182 "feed" => Some(Page::Feed),
128183 "library" => Some(Page::MainMenu(MainMenuPage::Library)),
129184 "channel" => {
130 if command.len() == 2 {
185 if command.len() != 3 {
131186 *framework.data.global.get_mut::<Message>().unwrap() =
132187 Message::Message(String::from("Usage: `loadpage channel {id/url}`"));
133188 return;
@@ -146,7 +201,7 @@ pub fn run_single_command(
146201 }
147202 }
148203 "video" => {
149 if command.len() == 2 {
204 if command.len() != 3 {
150205 *framework.data.global.get_mut::<Message>().unwrap() =
151206 Message::Message(String::from("Usage: `loadpage video {id/url}`"));
152207 return;
@@ -162,7 +217,7 @@ pub fn run_single_command(
162217 }
163218 }
164219 "playlist" => {
165 if command.len() == 2 {
220 if command.len() != 3 {
166221 *framework.data.global.get_mut::<Message>().unwrap() =
167222 Message::Message(String::from("Usage: `loadpage playlist {id/url}`"));
168223 return;