Skip to content

Commit

Permalink
Merge pull request #72 from myyrakle/refac/#71
Browse files Browse the repository at this point in the history
[#71] Command 플래그 관련 개선사항
  • Loading branch information
wHoIsDReAmer authored Mar 18, 2024
2 parents 33e3d6a + 04f80f5 commit eb54dd9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
20 changes: 0 additions & 20 deletions src/command/commands.rs

This file was deleted.

10 changes: 7 additions & 3 deletions src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use clap::Args;

/// Config options for the build system.
#[derive(Clone, Debug, Default, Deserialize, Args)]
pub struct ConfigOptionsInit {}
pub struct ConfigOptions {
/// 파일이 세팅될 경로
#[clap(long, short)]
pub config_path: Option<String>,
}

#[derive(Clone, Debug, Args)]
#[clap(name = "init")]
pub struct InitCommand {
pub struct Command {
#[clap(flatten)]
pub init: ConfigOptionsInit,
pub init: ConfigOptions,
}
25 changes: 19 additions & 6 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
pub mod commands;
pub use commands::*;

pub mod init;
pub use init::*;

pub mod run;
pub use run::*;

use clap::Parser;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Command {
#[clap(subcommand)]
pub action: SubCommand,
}

#[derive(clap::Subcommand, Debug)]
pub enum SubCommand {
/// 설정 파일 및 저장공간 초기화
Init(init::Command),
/// DB 서버 실행
Run(run::Command),
/// DB 클라이언트 실행
Client,
}
27 changes: 18 additions & 9 deletions src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ use clap::Args;

/// Config options for the build system.
#[derive(Clone, Debug, Default, Deserialize, Args)]
pub struct ConfigOptionsRun {
/// 포트
#[clap(name = "port", long)]
pub port: Option<u32>,
pub struct ConfigOptions {
#[clap(
name = "port",
default_value = "55555",
long,
short,
help = "Port to listen on"
)]
pub port: u32,

/// 호스트
#[clap(name = "host", long)]
pub host: Option<String>,
#[clap(
name = "host",
default_value = "0.0.0.0",
long,
help = "Hostname to listen on (IP or domain)"
)]
pub host: String,
}

#[derive(Clone, Debug, Args)]
#[clap(name = "run")]
pub struct RunCommand {
pub struct Command {
#[clap(flatten)]
pub value: ConfigOptionsRun,
pub value: ConfigOptions,
}
1 change: 0 additions & 1 deletion src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod predule;
pub mod server;
2 changes: 1 addition & 1 deletion src/constants/predule.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use super::server::*;

2 changes: 0 additions & 2 deletions src/constants/server.rs

This file was deleted.

7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ pub mod pgwire;
pub mod server;
pub mod utils;

use command::commands::{Command, SubCommand};
use constants::predule::{DEFAULT_HOST, DEFAULT_PORT};
use command::{Command, SubCommand};
use executor::predule::Executor;
use server::predule::{Server, ServerOption};

Expand All @@ -34,8 +33,8 @@ async fn main() -> Result<(), Box<dyn Error + Send>> {
}
SubCommand::Run(run) => {
let server_option = ServerOption {
port: run.value.port.unwrap_or(DEFAULT_PORT),
host: run.value.host.unwrap_or_else(|| DEFAULT_HOST.into()),
port: run.value.port,
host: run.value.host,
};
let server = Server::new(server_option);

Expand Down

0 comments on commit eb54dd9

Please sign in to comment.