aboutsummaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/args.rs b/src/args.rs
index 49fe276..a5bcfea 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -1,6 +1,7 @@
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::PathBuf;
use structopt::StructOpt;
+use port_check::free_local_port;
use crate::auth;
use crate::errors::ContextualError;
@@ -84,9 +85,16 @@ struct CLIArgs {
#[structopt(short = "o", long = "overwrite-files")]
overwrite_files: bool,
- /// Disable archive generation
- #[structopt(short = "r", long = "disable-archives")]
- disable_archives: bool,
+ /// Enable tar archive generation
+ #[structopt(short = "r", long = "enable-tar")]
+ enable_tar: bool,
+
+ /// Enable zip archive generation
+ ///
+ /// WARNING: Zipping large directories can result in out-of-memory exception
+ /// because zip generation is done in memory and cannot be sent on the fly
+ #[structopt(short = "z", long = "enable-zip")]
+ enable_zip: bool,
}
/// Checks wether an interface is valid, i.e. it can be parsed into an IP address
@@ -154,7 +162,7 @@ pub fn parse_args() -> crate::MiniserveConfig {
};
let random_route = if args.random_route {
- Some(nanoid::custom(6, &ROUTE_ALPHABET))
+ Some(nanoid::nanoid!(6, &ROUTE_ALPHABET))
} else {
None
};
@@ -163,10 +171,15 @@ pub fn parse_args() -> crate::MiniserveConfig {
let path_explicitly_chosen = args.path.is_some();
+ let port = match args.port {
+ 0 => free_local_port().expect("no free ports available"),
+ _ => args.port,
+ };
+
crate::MiniserveConfig {
verbose: args.verbose,
path: args.path.unwrap_or_else(|| PathBuf::from(".")),
- port: args.port,
+ port,
interfaces,
auth: args.auth,
path_explicitly_chosen,
@@ -176,7 +189,8 @@ pub fn parse_args() -> crate::MiniserveConfig {
index: args.index,
overwrite_files: args.overwrite_files,
file_upload: args.file_upload,
- archives: !args.disable_archives,
+ tar_enabled: args.enable_tar,
+ zip_enabled: args.enable_zip,
}
}