From b4b1fd8276129a63aa40a0c503cca83bcc824e1f Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Fri, 13 Apr 2018 10:33:27 +0100 Subject: [PATCH] Support --upload and --upload-path flags in arg parser, implement mock config file --- src/cli/cli.rs | 4 ++++ src/cli/config_file.rs | 28 ++++++++++++++++++++++++++++ src/cli/mod.rs | 4 +++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/cli/config_file.rs diff --git a/src/cli/cli.rs b/src/cli/cli.rs index 6e78922..6ed8e07 100644 --- a/src/cli/cli.rs +++ b/src/cli/cli.rs @@ -14,6 +14,8 @@ Options: -a=<addr>, --address=<addr> Address to bind to (e.g. 10.0.0.15); defaults to localhost -c=<path>, --config=<path> Path to the .swerve config file -t=<num>, --threads=<num> Number of worker threads to use for serving files; defaults to 32 + -u, --upload Support file uploads to '/upload' + -U=<path>, --upload-path=<path> Set the url path that will accept file uploads. Implies -u if not present "; #[derive(Debug, Deserialize, Clone)] @@ -26,4 +28,6 @@ pub struct Args { pub flag_help: bool, pub flag_quiet: bool, pub flag_no_index: bool, + pub flag_upload: bool, + pub flag_upload_path: Option<String>, } \ No newline at end of file diff --git a/src/cli/config_file.rs b/src/cli/config_file.rs new file mode 100644 index 0000000..538dac1 --- /dev/null +++ b/src/cli/config_file.rs @@ -0,0 +1,28 @@ +use std::path::Path; +use std::convert::AsRef; +use std::io::prelude::*; +use std::io; +use std::fs::File; + +pub enum HandlerMethod { + Log, + File, +} + +pub struct SwerveConfig { + pub field_handling: HandlerMethod, + pub file_handling: HandlerMethod, +} + +impl SwerveConfig { + pub fn from_file<P>(path: P) -> io::Result<SwerveConfig> where P: AsRef<Path> { +// let mut file = File::open(path)?; +// let mut buffer = String::new(); +// file.read_to_string(buffer)?; + + Ok(SwerveConfig { + field_handling: HandlerMethod::Log, + file_handling: HandlerMethod::Log, + }) + } +} \ No newline at end of file diff --git a/src/cli/mod.rs b/src/cli/mod.rs index c983ad5..3f293ea 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,3 +1,5 @@ mod cli; +mod config_file; -pub use self::cli::{Args, USAGE}; \ No newline at end of file +pub use self::cli::{Args, USAGE}; +pub use self::config_file::{HandlerMethod, SwerveConfig}; \ No newline at end of file -- GitLab