index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-01-24 21:31:43.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-01-24 21:31:43.0 +00:00:00
commit
77b07be018ef22894fc0337de6d70ae19067a5ae [patch]
tree
86ce71db528700362efc2fb2f84c06ae8624286a
parent
300337ec2e39253a92283e636bb91b6b44b02cbf
download
77b07be018ef22894fc0337de6d70ae19067a5ae.tar.gz

feat: cli argument aliases



Diff

 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 <assets>
    -f, --assets <assets>
            Assets directory path for add cache headers functionality [env: SERVER_ASSETS=]  [default: ./public/assets]

        --cors-allow-origins <cors-allow-origins>
    -c, --cors-allow-origins <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>                                Host address (E.g 127.0.0.1) [env: SERVER_HOST=]  [default: [::]]
        --log-level <log-level>
    -a, --host <host>                                Host address (E.g 127.0.0.1) [env: SERVER_HOST=]  [default: [::]]
    -g, --log-level <log-level>
            Specify a logging level in lower case [env: SERVER_LOG_LEVEL=]  [default: error]

        --name <name>                                Name for server [env: SERVER_NAME=]  [default: my-static-server]
    -l, --name <name>                                Name for server [env: SERVER_NAME=]  [default: my-static-server]
        --page404 <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 <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 <port>                                Host port [env: SERVER_PORT=]  [default: 80]
        --root <root>
    -p, --port <port>                                Host port [env: SERVER_PORT=]  [default: 80]
    -d, --root <root>
            Root directory path of static files [env: SERVER_ROOT=]  [default: ./public]

        --tls <tls>                                  Enables TLS/SSL support [env: SERVER_TLS=]
    -t, --tls <tls>                                  Enables TLS/SSL support [env: SERVER_TLS=]
        --tls-pkcs12 <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<u16>,

    #[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<String>,
    #[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,
}