Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#71] Command 플래그 관련 개선사항 #72

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading