Skip to content

Commit 97cd9a7

Browse files
committed
feat(cli): service option for cli
1 parent ce69b2b commit 97cd9a7

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

src/http-server/src/cli/command/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod start;
1+
pub mod start;
22

33
use clap::Parser;
44

src/http-server/src/cli/command/start.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::net::IpAddr;
22
use std::process::exit;
3+
use std::str::FromStr;
34
use std::sync::Arc;
45

56
use anyhow::Result;
@@ -12,6 +13,24 @@ use crate::server::Server;
1213

1314
const THREAD_NAME: &str = "http-server";
1415

16+
#[derive(Clone, Debug, Parser)]
17+
pub enum Service {
18+
FileServer,
19+
FileExplorer,
20+
}
21+
22+
impl FromStr for Service {
23+
type Err = String;
24+
25+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
26+
match s {
27+
"file-server" => Ok(Service::FileServer),
28+
"file-explorer" => Ok(Service::FileExplorer),
29+
_ => Err(format!("Invalid service: {}", s)),
30+
}
31+
}
32+
}
33+
1534
#[derive(Debug, Parser)]
1635
pub struct StartOpt {
1736
/// Host (IP) to bind the server
@@ -23,9 +42,9 @@ pub struct StartOpt {
2342
/// Enable CORS with a permissive policy
2443
#[clap(long, default_value = "false")]
2544
pub cors: bool,
26-
/// Use widely supported File Explorer UI
27-
#[clap(long, default_value = "false")]
28-
pub legacy_ui: bool,
45+
/// Service to run
46+
#[clap(long, default_value = "file-explorer")]
47+
pub service: Service,
2948
}
3049

3150
impl From<&StartOpt> for Config {
@@ -34,7 +53,7 @@ impl From<&StartOpt> for Config {
3453
host: val.host,
3554
port: val.port,
3655
cors: val.cors,
37-
legacy_ui: val.legacy_ui,
56+
service: val.service.clone().into(),
3857
}
3958
}
4059
}

src/http-server/src/config.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ use std::str::FromStr;
33

44
use anyhow::{Error, Result, bail};
55

6+
#[derive(Clone, Debug)]
7+
pub enum Service {
8+
FileServer {
9+
root_directory: String,
10+
basic_auth: Option<BasicAuth>,
11+
},
12+
FileExplorer {
13+
root_directory: String,
14+
basic_auth: Option<BasicAuth>,
15+
},
16+
}
17+
18+
impl From<crate::cli::command::start::Service> for Service {
19+
fn from(val: crate::cli::command::start::Service) -> Self {
20+
match val {
21+
crate::cli::command::start::Service::FileServer => Service::FileServer {
22+
root_directory: "./".into(),
23+
basic_auth: None,
24+
},
25+
crate::cli::command::start::Service::FileExplorer => Service::FileExplorer {
26+
root_directory: "./".into(),
27+
basic_auth: None,
28+
},
29+
}
30+
}
31+
}
32+
633
#[derive(Clone, Debug)]
734
pub struct Config {
835
/// The IP address to bind to.
@@ -11,8 +38,8 @@ pub struct Config {
1138
pub port: u16,
1239
/// Enable CORS with a permissive policy.
1340
pub cors: bool,
14-
/// Enable Legacy File Explorer UI.
15-
pub legacy_ui: bool,
41+
/// Service
42+
pub service: Service,
1643
}
1744

1845
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)