-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move gui and cli versions to different files
- Move common code from main to dedicated files for reusability - Optimize on the cross-build script
- Loading branch information
Showing
10 changed files
with
403 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
|
||
use clap::Parser; | ||
use clap::ArgAction; | ||
|
||
use crate::Protocol; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about = "Quick-Serve", long_about = "Instant file serving made easy")] | ||
pub struct Cli { | ||
|
||
// TODO: Still have to figure a way to **not** show the | ||
// headless option when running headless | ||
#[arg( | ||
help = "Headless", | ||
long, required = false, | ||
action = ArgAction::SetTrue, | ||
)] pub headless: bool, | ||
|
||
#[arg( | ||
help = "Bind IP", | ||
short, long, required = false, | ||
default_value = "127.0.0.1", | ||
value_name = "IP", | ||
require_equals = true, | ||
)] pub bind_ip: String, | ||
|
||
#[arg( | ||
help = "Directory to serve", | ||
short = 'd', long, required = false, | ||
default_value = "/tmp/", | ||
value_name = "PATH", | ||
require_equals = true, | ||
)] pub serve_dir: String, | ||
|
||
#[arg( | ||
help = "Verbose logging", | ||
short, long, required = false, | ||
action = clap::ArgAction::Count, | ||
)] pub verbose: u8, | ||
|
||
#[arg( | ||
default_missing_value = Protocol::Http.get_default_port().to_string(), | ||
help = format!("Start the HTTP server [default port: {}]", Protocol::Http.get_default_port().to_string()), | ||
long, required = false, | ||
num_args = 0..=1, | ||
require_equals = true, | ||
value_name = "PORT", | ||
)] pub http: Option<u32>, | ||
|
||
#[arg( | ||
default_missing_value = Protocol::Ftp.get_default_port().to_string(), | ||
help = format!("Start the FTP server [default port: {}]", Protocol::Ftp.get_default_port().to_string()), | ||
long, required = false, | ||
num_args = 0..=1, | ||
require_equals = true, | ||
value_name = "PORT", | ||
)] pub ftp: Option<u32>, | ||
|
||
#[arg( | ||
default_missing_value = Protocol::Tftp.get_default_port().to_string(), | ||
help = format!("Start the TFTP server [default port: {}]", Protocol::Tftp.get_default_port().to_string()), | ||
long, required = false, | ||
num_args = 0..=1, | ||
require_equals = true, | ||
value_name = "PORT", | ||
)] pub tftp: Option<u32>, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
pub use args::*; | ||
pub use messages::*; | ||
pub use utils::*; | ||
|
||
// Import and re-export the submodule files. | ||
pub mod args; | ||
pub mod messages; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::process::exit; | ||
|
||
use log::info; | ||
use log::warn; | ||
|
||
pub fn setup_ctrlc_handler() { | ||
//////////////////////////////////////////////////////////////////////// | ||
// Ctrl+c handler from here on | ||
//////////////////////////////////////////////////////////////////////// | ||
// TODO: only add handle if any server has been invoked | ||
// Add handle for Ctrl+C | ||
tokio::spawn(async move { | ||
ctrlc::set_handler(move || { | ||
warn!("Ctrl+C received. Closing connections and exiting."); | ||
//TODO: send a message to stop all servers and wait 10 | ||
|
||
exit(1); | ||
}).expect("Error setting Ctrl+C handler"); | ||
info!("Press Ctrl+C to exit."); | ||
}); | ||
} |
Oops, something went wrong.