Skip to content

Commit 9d61434

Browse files
authored
Update main.rs
1 parent b5675c1 commit 9d61434

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

hacker/src/main.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clap::{Parser, Subcommand};
22
use colored::*;
3-
use hacker::{display_ascii, display_help, handle_run, handle_system, handle_unpack, handle_update, play_game, run_command_with_spinner, RunCommands, SystemCommands, UnpackCommands};
3+
use hacker::{display_ascii, handle_run, handle_system, handle_unpack, handle_update, play_game, run_command_with_spinner, RunCommands, SystemCommands, UnpackCommands};
4+
use std::process::Command;
45
#[derive(Parser)]
56
#[command(name = "hacker", about = "A vibrant CLI tool for managing hacker tools, gaming, and system utilities", version = "1.0.0")]
67
struct Cli {
@@ -16,6 +17,8 @@ enum Commands {
1617
},
1718
/// Display help information and list available commands
1819
Help,
20+
/// Display help UI
21+
HelpUi,
1922
/// Placeholder for install command
2023
Install {
2124
package: String,
@@ -60,12 +63,41 @@ enum Commands {
6063
HackerLang,
6164
/// Display HackerOS ASCII art
6265
Ascii,
66+
/// Enter interactive Hacker shell mode
67+
Shell,
6368
}
6469
fn main() {
6570
let cli = Cli::parse();
6671
match cli.command {
6772
Commands::Unpack { unpack_command } => handle_unpack(unpack_command),
68-
Commands::Help => display_help(),
73+
Commands::Help => {
74+
let home = std::env::var("HOME").unwrap_or_default();
75+
let help_bin = format!("{}/.hackeros/hacker-help", home);
76+
match Command::new(&help_bin).status() {
77+
Ok(status) => {
78+
if !status.success() {
79+
println!("{}", "Error running hacker-help. Ensure it's installed and executable in ~/.hackeros/".red().bold().on_black());
80+
}
81+
}
82+
Err(e) => {
83+
println!("{}", format!("Failed to execute hacker-help: {}", e).red().bold().on_black());
84+
}
85+
}
86+
}
87+
Commands::HelpUi => {
88+
let home = std::env::var("HOME").unwrap_or_default();
89+
let help_bin = format!("{}/.hackeros/hacker-help", home);
90+
match Command::new(&help_bin).status() {
91+
Ok(status) => {
92+
if !status.success() {
93+
println!("{}", "Error running hacker-help. Ensure it's installed and executable in ~/.hackeros/".red().bold().on_black());
94+
}
95+
}
96+
Err(e) => {
97+
println!("{}", format!("Failed to execute hacker-help: {}", e).red().bold().on_black());
98+
}
99+
}
100+
}
69101
Commands::Install { package } => println!("{}", format!("Install command is a placeholder for: {}", package).yellow().bold().on_black()),
70102
Commands::Remove { package } => println!("{}", format!("Remove command is a placeholder for: {}", package).yellow().bold().on_black()),
71103
Commands::AptInstall { package } => run_command_with_spinner("sudo", vec!["apt", "install", "-y", &package], "Running apt install"),
@@ -85,5 +117,19 @@ fn main() {
85117
println!("{}", "========== End of Info ==========".magenta().bold().on_black());
86118
}
87119
Commands::Ascii => display_ascii(),
120+
Commands::Shell => {
121+
let home = std::env::var("HOME").unwrap_or_default();
122+
let shell_bin = format!("{}/.hackeros/hacker-shell", home);
123+
match Command::new(&shell_bin).status() {
124+
Ok(status) => {
125+
if !status.success() {
126+
println!("{}", "Error running hacker-shell. Ensure it's installed and executable in ~/.hackeros/".red().bold().on_black());
127+
}
128+
}
129+
Err(e) => {
130+
println!("{}", format!("Failed to execute hacker-shell: {}", e).red().bold().on_black());
131+
}
132+
}
133+
}
88134
}
89135
}

0 commit comments

Comments
 (0)