aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--Cargo.toml2
-rw-r--r--README.md85
-rw-r--r--src/args.rs110
4 files changed, 152 insertions, 46 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f092018..8cf312a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate
+- Allow parameters to be provided via environment variables [#1160](https://github.com/svenstaro/miniserve/pull/1160)
## [0.23.2] - 2023-04-28
- Build Windows build with static CRT [#1107](https://github.com/svenstaro/miniserve/pull/1107)
diff --git a/Cargo.toml b/Cargo.toml
index ae16d29..d79600b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,7 +28,7 @@ anyhow = "1"
bytesize = "1"
chrono = "0.4"
chrono-humanize = "0.2"
-clap = { version = "4", features = ["derive", "cargo", "wrap_help", "deprecated"] }
+clap = { version = "4", features = ["derive", "cargo", "wrap_help", "deprecated", "env"] }
clap_complete = "4"
clap_mangen = "0.2"
comrak = { version = "0.18", default-features = false }
diff --git a/README.md b/README.md
index 1c4f522..56701db 100644
--- a/README.md
+++ b/README.md
@@ -121,114 +121,167 @@ Some mobile browsers like Firefox on Android will offer to open the camera app w
[PATH]
Which path to serve
+ [env: MINISERVE_PATH=]
+
Options:
-v, --verbose
Be verbose, includes emitting access logs
+ [env: MINISERVE_VERBOSE=]
+
--index <INDEX>
The name of a directory index file to serve, like "index.html"
- Normally, when miniserve serves a directory, it creates a listing for that
- directory. However, if a directory contains this file, miniserve will serve that
- file instead.
+ Normally, when miniserve serves a directory, it creates a listing for that directory.
+ However, if a directory contains this file, miniserve will serve that file instead.
+
+ [env: MINISERVE_INDEX=]
--spa
Activate SPA (Single Page Application) mode
- This will cause the file given by --index to be served for all non-existing file
- paths. In effect, this will serve the index file whenever a 404 would otherwise
- occur in order to allow the SPA router to handle the request instead.
+ This will cause the file given by --index to be served for all non-existing file paths. In
+ effect, this will serve the index file whenever a 404 would otherwise occur in order to
+ allow the SPA router to handle the request instead.
+
+ [env: MINISERVE_SPA=]
-p, --port <PORT>
Port to use
+ [env: MINISERVE_PORT=]
[default: 8080]
- -i, --interfaces <INTERFACES>...
+ -i, --interfaces <INTERFACES>
Interface to listen on
- -a, --auth <AUTH>...
- Set authentication. Currently supported formats: username:password,
- username:sha256:hash, username:sha512:hash (e.g. joe:123,
+ [env: MINISERVE_INTERFACE=]
+
+ -a, --auth <AUTH>
+ Set authentication. Currently supported formats: username:password, username:sha256:hash,
+ username:sha512:hash (e.g. joe:123,
joe:sha256:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3)
+ [env: MINISERVE_AUTH=]
+
--route-prefix <ROUTE_PREFIX>
Use a specific route prefix
+ [env: MINISERVE_ROUTE_PREFIX=]
+
--random-route
Generate a random 6-hexdigit route
+ [env: MINISERVE_RANDOM_ROUTE=]
+
-P, --no-symlinks
Hide symlinks in listing and prevent them from being followed
+ [env: MINISERVE_NO_SYMLINKS=]
+
-H, --hidden
Show hidden files
+ [env: MINISERVE_HIDDEN=]
+
-c, --color-scheme <COLOR_SCHEME>
Default color scheme
+ [env: MINISERVE_COLOR_SCHEME=]
[default: squirrel]
[possible values: squirrel, archlinux, zenburn, monokai]
-d, --color-scheme-dark <COLOR_SCHEME_DARK>
Default color scheme
+ [env: MINISERVE_COLOR_SCHEME_DARK=]
[default: archlinux]
[possible values: squirrel, archlinux, zenburn, monokai]
-q, --qrcode
Enable QR code display
+ [env: MINISERVE_QRCODE=]
+
-u, --upload-files [<ALLOWED_UPLOAD_DIR>]
Enable file uploading (and optionally specify for which directory)
+ [env: MINISERVE_ALLOWED_UPLOAD_DIR=]
+
-U, --mkdir
Enable creating directories
+ [env: MINISERVE_MKDIR_ENABLED=]
+
-m, --media-type <MEDIA_TYPE>
Specify uploadable media types
+ [env: MINISERVE_MEDIA_TYPE=]
[possible values: image, audio, video]
-M, --raw-media-type <MEDIA_TYPE_RAW>
Directly specify the uploadable media type expression
+ [env: MINISERVE_RAW_MEDIA_TYPE=]
+
-o, --overwrite-files
Enable overriding existing files during file upload
+ [env: OVERWRITE_FILES=]
+
-r, --enable-tar
Enable uncompressed tar archive generation
+ [env: MINISERVE_ENABLE_TAR=]
+
-g, --enable-tar-gz
Enable gz-compressed tar archive generation
+ [env: MINISERVE_ENABLE_TAR_GZ=]
+
-z, --enable-zip
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
+ [env: MINISERVE_ENABLE_ZIP=]
+
-D, --dirs-first
List directories first
+ [env: MINISERVE_DIRS_FIRST=]
+
-t, --title <TITLE>
Shown instead of host in page title and heading
- --header <HEADER>...
+ [env: MINISERVE_TITLE=]
+
+ --header <HEADER>
Set custom header for responses
+ [env: MINISERVE_HEADER=]
+
-l, --show-symlink-info
Visualize symlinks in directory listing
+ [env: MINISERVE_SHOW_SYMLINK_INFO=]
+
-F, --hide-version-footer
Hide version footer
+ [env: MINISERVE_HIDE_VERSION_FOOTER=]
+
--hide-theme-selector
Hide theme selector
+ [env: MINISERVE_HIDE_THEME_SELECTOR=]
+
-W, --show-wget-footer
If enabled, display a wget command to recursively download the current directory
+ [env: MINISERVE_SHOW_WGET_FOOTER=]
+
--print-completions <shell>
Generate completion file for a shell
@@ -240,17 +293,23 @@ Some mobile browsers like Firefox on Android will offer to open the camera app w
--tls-cert <TLS_CERT>
TLS certificate to use
+ [env: MINISERVE_TLS_CERT=]
+
--tls-key <TLS_KEY>
TLS private key to use
+ [env: MINISERVE_TLS_KEY=]
+
--readme
Enable README.md rendering in directories
+ [env: MINISERVE_README=]
+
-h, --help
- Print help information (use `-h` for a summary)
+ Print help (see a summary with '-h')
-V, --version
- Print version information
+ Print version
## How to install
diff --git a/src/args.rs b/src/args.rs
index 243eecf..f7b42f1 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -19,18 +19,18 @@ pub enum MediaType {
#[command(name = "miniserve", author, about, version)]
pub struct CliArgs {
/// Be verbose, includes emitting access logs
- #[arg(short = 'v', long = "verbose")]
+ #[arg(short = 'v', long = "verbose", env = "MINISERVE_VERBOSE")]
pub verbose: bool,
/// Which path to serve
- #[arg(value_hint = ValueHint::AnyPath)]
+ #[arg(value_hint = ValueHint::AnyPath, env = "MINISERVE_PATH")]
pub path: Option<PathBuf>,
/// The name of a directory index file to serve, like "index.html"
///
/// Normally, when miniserve serves a directory, it creates a listing for that directory.
/// However, if a directory contains this file, miniserve will serve that file instead.
- #[arg(long, value_hint = ValueHint::FilePath)]
+ #[arg(long, value_hint = ValueHint::FilePath, env = "MINISERVE_INDEX")]
pub index: Option<PathBuf>,
/// Activate SPA (Single Page Application) mode
@@ -38,11 +38,16 @@ pub struct CliArgs {
/// This will cause the file given by --index to be served for all non-existing file paths. In
/// effect, this will serve the index file whenever a 404 would otherwise occur in order to
/// allow the SPA router to handle the request instead.
- #[arg(long, requires = "index")]
+ #[arg(long, requires = "index", env = "MINISERVE_SPA")]
pub spa: bool,
/// Port to use
- #[arg(short = 'p', long = "port", default_value = "8080")]
+ #[arg(
+ short = 'p',
+ long = "port",
+ default_value = "8080",
+ env = "MINISERVE_PORT"
+ )]
pub port: u16,
/// Interface to listen on
@@ -50,30 +55,41 @@ pub struct CliArgs {
short = 'i',
long = "interfaces",
value_parser(parse_interface),
- num_args(1)
+ num_args(1),
+ env = "MINISERVE_INTERFACE"
)]
pub interfaces: Vec<IpAddr>,
/// Set authentication. Currently supported formats:
/// username:password, username:sha256:hash, username:sha512:hash
/// (e.g. joe:123, joe:sha256:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3)
- #[arg(short = 'a', long = "auth", value_parser(parse_auth), num_args(1))]
+ #[arg(
+ short = 'a',
+ long = "auth",
+ value_parser(parse_auth),
+ num_args(1),
+ env = "MINISERVE_AUTH"
+ )]
pub auth: Vec<auth::RequiredAuth>,
/// Use a specific route prefix
- #[arg(long = "route-prefix")]
+ #[arg(long = "route-prefix", env = "MINISERVE_ROUTE_PREFIX")]
pub route_prefix: Option<String>,
/// Generate a random 6-hexdigit route
- #[arg(long = "random-route", conflicts_with("route_prefix"))]
+ #[arg(
+ long = "random-route",
+ conflicts_with("route_prefix"),
+ env = "MINISERVE_RANDOM_ROUTE"
+ )]
pub random_route: bool,
/// Hide symlinks in listing and prevent them from being followed
- #[arg(short = 'P', long = "no-symlinks")]
+ #[arg(short = 'P', long = "no-symlinks", env = "MINISERVE_NO_SYMLINKS")]
pub no_symlinks: bool,
/// Show hidden files
- #[arg(short = 'H', long = "hidden")]
+ #[arg(short = 'H', long = "hidden", env = "MINISERVE_HIDDEN")]
pub hidden: bool,
/// Default color scheme
@@ -81,7 +97,8 @@ pub struct CliArgs {
short = 'c',
long = "color-scheme",
default_value = "squirrel",
- ignore_case = true
+ ignore_case = true,
+ env = "MINISERVE_COLOR_SCHEME"
)]
pub color_scheme: ThemeSlug,
@@ -90,24 +107,35 @@ pub struct CliArgs {
short = 'd',
long = "color-scheme-dark",
default_value = "archlinux",
- ignore_case = true
+ ignore_case = true,
+ env = "MINISERVE_COLOR_SCHEME_DARK"
)]
pub color_scheme_dark: ThemeSlug,
/// Enable QR code display
- #[arg(short = 'q', long = "qrcode")]
+ #[arg(short = 'q', long = "qrcode", env = "MINISERVE_QRCODE")]
pub qrcode: bool,
/// Enable file uploading (and optionally specify for which directory)
- #[arg(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','))]
+ #[arg(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','), env = "MINISERVE_ALLOWED_UPLOAD_DIR")]
pub allowed_upload_dir: Option<Vec<PathBuf>>,
/// Enable creating directories
- #[arg(short = 'U', long = "mkdir", requires = "allowed_upload_dir")]
+ #[arg(
+ short = 'U',
+ long = "mkdir",
+ requires = "allowed_upload_dir",
+ env = "MINISERVE_MKDIR_ENABLED"
+ )]
pub mkdir_enabled: bool,
/// Specify uploadable media types
- #[arg(short = 'm', long = "media-type", requires = "allowed_upload_dir")]
+ #[arg(
+ short = 'm',
+ long = "media-type",
+ requires = "allowed_upload_dir",
+ env = "MINISERVE_MEDIA_TYPE"
+ )]
pub media_type: Option<Vec<MediaType>>,
/// Directly specify the uploadable media type expression
@@ -115,55 +143,73 @@ pub struct CliArgs {
short = 'M',
long = "raw-media-type",
requires = "allowed_upload_dir",
- conflicts_with = "media_type"
+ conflicts_with = "media_type",
+ env = "MINISERVE_RAW_MEDIA_TYPE"
)]
pub media_type_raw: Option<String>,
/// Enable overriding existing files during file upload
- #[arg(short = 'o', long = "overwrite-files")]
+ #[arg(short = 'o', long = "overwrite-files", env = "OVERWRITE_FILES")]
pub overwrite_files: bool,
/// Enable uncompressed tar archive generation
- #[arg(short = 'r', long = "enable-tar")]
+ #[arg(short = 'r', long = "enable-tar", env = "MINISERVE_ENABLE_TAR")]
pub enable_tar: bool,
/// Enable gz-compressed tar archive generation
- #[arg(short = 'g', long = "enable-tar-gz")]
+ #[arg(short = 'g', long = "enable-tar-gz", env = "MINISERVE_ENABLE_TAR_GZ")]
pub enable_tar_gz: 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
- #[arg(short = 'z', long = "enable-zip")]
+ #[arg(short = 'z', long = "enable-zip", env = "MINISERVE_ENABLE_ZIP")]
pub enable_zip: bool,
/// List directories first
- #[arg(short = 'D', long = "dirs-first")]
+ #[arg(short = 'D', long = "dirs-first", env = "MINISERVE_DIRS_FIRST")]
pub dirs_first: bool,
/// Shown instead of host in page title and heading
- #[arg(short = 't', long = "title")]
+ #[arg(short = 't', long = "title", env = "MINISERVE_TITLE")]
pub title: Option<String>,
/// Set custom header for responses
- #[arg(long = "header", value_parser(parse_header), num_args(1))]
+ #[arg(
+ long = "header",
+ value_parser(parse_header),
+ num_args(1),
+ env = "MINISERVE_HEADER"
+ )]
pub header: Vec<HeaderMap>,
/// Visualize symlinks in directory listing
- #[arg(short = 'l', long = "show-symlink-info")]
+ #[arg(
+ short = 'l',
+ long = "show-symlink-info",
+ env = "MINISERVE_SHOW_SYMLINK_INFO"
+ )]
pub show_symlink_info: bool,
/// Hide version footer
- #[arg(short = 'F', long = "hide-version-footer")]
+ #[arg(
+ short = 'F',
+ long = "hide-version-footer",
+ env = "MINISERVE_HIDE_VERSION_FOOTER"
+ )]
pub hide_version_footer: bool,
/// Hide theme selector
- #[arg(long = "hide-theme-selector")]
+ #[arg(long = "hide-theme-selector", env = "MINISERVE_HIDE_THEME_SELECTOR")]
pub hide_theme_selector: bool,
/// If enabled, display a wget command to recursively download the current directory
- #[arg(short = 'W', long = "show-wget-footer")]
+ #[arg(
+ short = 'W',
+ long = "show-wget-footer",
+ env = "MINISERVE_SHOW_WGET_FOOTER"
+ )]
pub show_wget_footer: bool,
/// Generate completion file for a shell
@@ -176,16 +222,16 @@ pub struct CliArgs {
/// TLS certificate to use
#[cfg(feature = "tls")]
- #[arg(long = "tls-cert", requires = "tls_key", value_hint = ValueHint::FilePath)]
+ #[arg(long = "tls-cert", requires = "tls_key", value_hint = ValueHint::FilePath, env = "MINISERVE_TLS_CERT")]
pub tls_cert: Option<PathBuf>,
/// TLS private key to use
#[cfg(feature = "tls")]
- #[arg(long = "tls-key", requires = "tls_cert", value_hint = ValueHint::FilePath)]
+ #[arg(long = "tls-key", requires = "tls_cert", value_hint = ValueHint::FilePath, env = "MINISERVE_TLS_KEY")]
pub tls_key: Option<PathBuf>,
/// Enable README.md rendering in directories
- #[arg(long)]
+ #[arg(long, env = "MINISERVE_README")]
pub readme: bool,
}