From 77b07be018ef22894fc0337de6d70ae19067a5ae Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Sun, 24 Jan 2021 22:31:43 +0100 Subject: [PATCH] feat: cli argument aliases --- README.md | 16 ++++++++-------- src/config.rs | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c5fbc28..dbe304d 100644 --- a/README.md +++ b/README.md @@ -70,28 +70,28 @@ FLAGS: -V, --version Prints version information OPTIONS: - --assets + -f, --assets Assets directory path for add cache headers functionality [env: SERVER_ASSETS=] [default: ./public/assets] - --cors-allow-origins + -c, --cors-allow-origins Specify a CORS list of allowed origin hosts separated by comas with no whitespaces. Host ports or protocols aren't being checked. Use an asterisk (*) to allow any host [env: SERVER_CORS_ALLOW_ORIGINS=] [default: ] - --host Host address (E.g 127.0.0.1) [env: SERVER_HOST=] [default: [::]] - --log-level + -a, --host Host address (E.g 127.0.0.1) [env: SERVER_HOST=] [default: [::]] + -g, --log-level Specify a logging level in lower case [env: SERVER_LOG_LEVEL=] [default: error] - --name Name for server [env: SERVER_NAME=] [default: my-static-server] + -l, --name Name for server [env: SERVER_NAME=] [default: my-static-server] --page404 HTML file path for 404 errors. If path is not specified or simply don't exists then server will use a generic HTML error message [env: SERVER_ERROR_PAGE_404=] [default: ./public/404.html] --page50x HTML file path for 50x errors. If path is not specified or simply don't exists then server will use a generic HTML error message [env: SERVER_ERROR_PAGE_50X=] [default: ./public/50x.html] - --port Host port [env: SERVER_PORT=] [default: 80] - --root + -p, --port Host port [env: SERVER_PORT=] [default: 80] + -d, --root Root directory path of static files [env: SERVER_ROOT=] [default: ./public] - --tls Enables TLS/SSL support [env: SERVER_TLS=] + -t, --tls Enables TLS/SSL support [env: SERVER_TLS=] --tls-pkcs12 A cryptographic identity PKCS #12 bundle file path containing a X509 certificate along with its corresponding private key and chain of certificates to a trusted root [env: SERVER_TLS_PKCS12=] [default: ] diff --git a/src/config.rs b/src/config.rs index a3ce7b6..306cb30 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,21 +3,36 @@ use structopt::StructOpt; /// A blazing fast static files-serving web server powered by Rust Iron #[derive(Debug, StructOpt)] pub struct Options { - #[structopt(long, default_value = "my-static-server", env = "SERVER_NAME")] + #[structopt( + long, + short = "l", + default_value = "my-static-server", + env = "SERVER_NAME" + )] /// Name for server pub name: String, - #[structopt(long, default_value = "[::]", env = "SERVER_HOST")] + + #[structopt(long, short = "a", default_value = "[::]", env = "SERVER_HOST")] /// Host address (E.g 127.0.0.1) pub host: String, - #[structopt(long, default_value = "80", env = "SERVER_PORT")] + + #[structopt(long, short = "p", default_value = "80", env = "SERVER_PORT")] /// Host port pub port: u16, - #[structopt(long, default_value = "./public", env = "SERVER_ROOT")] + + #[structopt(long, short = "d", default_value = "./public", env = "SERVER_ROOT")] /// Root directory path of static files pub root: String, - #[structopt(long, default_value = "./public/assets", env = "SERVER_ASSETS")] + + #[structopt( + long, + short = "f", + default_value = "./public/assets", + env = "SERVER_ASSETS" + )] /// Assets directory path for add cache headers functionality pub assets: String, + #[structopt( long, default_value = "./public/50x.html", @@ -25,6 +40,7 @@ pub struct Options { )] /// HTML file path for 50x errors. If path is not specified or simply don't exists then server will use a generic HTML error message. pub page50x: String, + #[structopt( long, default_value = "./public/404.html", @@ -32,25 +48,37 @@ pub struct Options { )] /// HTML file path for 404 errors. If path is not specified or simply don't exists then server will use a generic HTML error message. pub page404: String, - #[structopt(long, env = "SERVER_TLS")] + + #[structopt(long, short = "t", env = "SERVER_TLS")] /// Enables TLS/SSL support. pub tls: bool, + #[structopt(long, default_value = "", env = "SERVER_TLS_PKCS12")] /// A cryptographic identity PKCS #12 bundle file path containing a X509 certificate along with its corresponding private key and chain of certificates to a trusted root. pub tls_pkcs12: String, + #[structopt(long, default_value = "", env = "SERVER_TLS_PKCS12_PASSWD")] /// A specified password to decrypt the private key. pub tls_pkcs12_passwd: String, + #[structopt(long, env = "SERVER_TLS_REDIRECT_FROM")] /// Host port for redirecting HTTP requests to HTTPS. This option enables the HTTP redirect feature. pub tls_redirect_from: Option, + #[structopt(long, env = "SERVER_TLS_REDIRECT_HOST")] /// Host name of HTTPS site for redirecting HTTP requests to. Defaults to host address. pub tls_redirect_host: Option, - #[structopt(long, default_value = "error", env = "SERVER_LOG_LEVEL")] + + #[structopt(long, short = "g", default_value = "error", env = "SERVER_LOG_LEVEL")] /// Specify a logging level in lower case. pub log_level: String, - #[structopt(long, default_value = "", env = "SERVER_CORS_ALLOW_ORIGINS")] + + #[structopt( + long, + short = "c", + default_value = "", + env = "SERVER_CORS_ALLOW_ORIGINS" + )] /// Specify a CORS list of allowed origin hosts separated by comas with no whitespaces. Host ports or protocols aren't being checked. Use an asterisk (*) to allow any host. pub cors_allow_origins: String, } -- libgit2 1.7.2