dbeel 0.1.0

dbeel is a fast and minimal distributed thread-per-core document database.
Documentation
use std::ffi::OsString;

use clap::Parser;

#[derive(Parser, Debug, Clone)]
#[command(author, version, about, long_about = None)]
/// A stupid database, by Tony Solomonik.
pub struct Args {
    #[clap(
        short,
        long,
        help = "Unique node name, used to differentiate between nodes for \
                distribution of load.",
        default_value = "dbeel"
    )]
    pub name: String,

    #[clap(
        short,
        long,
        help = "The seed nodes for service discovery of all nodes.
Expected format is <hostname/ip>:<port>.",
        num_args = 0..,
    )]
    pub seed_nodes: Vec<String>,

    #[clap(
        short,
        long,
        help = "Listen hostname / ip.",
        default_value = "127.0.0.1"
    )]
    pub ip: String,

    #[clap(
        short,
        long,
        help = "Server port base.
Each shard has a different port calculated by <port_base> + \
                <cpu_id>.
This port is for listening on client requests.",
        default_value = "10000"
    )]
    pub port: u16,

    #[clap(
        short,
        long,
        help = "Database files directory.",
        default_value = "/tmp/dbeel"
    )]
    pub dir: String,

    #[clap(
        long,
        help = "Default number of nodes (replicas) that hold a copy for a \
specific key for tunable availability / consistency, when the replication \
factor is not set in a create collection request.",
        default_value = "1"
    )]
    pub default_replication_factor: u16,

    #[clap(
        long,
        help = "Remote shard port base.
This port is for listening for distributed messages from \
                remote shards.",
        default_value = "20000"
    )]
    pub remote_shard_port: u16,

    #[clap(
        long,
        help = "Remote shard connect timeout in milliseconds.",
        default_value = "5000"
    )]
    pub remote_shard_connect_timeout: u64,

    #[clap(
        long,
        help = "Remote shard write request timeout in milliseconds.",
        default_value = "15000"
    )]
    pub remote_shard_write_timeout: u64,

    #[clap(
        long,
        help = "Remote shard read request timeout in milliseconds.",
        default_value = "15000"
    )]
    pub remote_shard_read_timeout: u64,

    #[clap(
        long,
        help = "Gossip UDP server port.
This port is for listening for gossip messages from \
                remote nodes.",
        default_value = "30000"
    )]
    pub gossip_port: u16,

    #[clap(long, help = "Gossip number of nodes fanout.", default_value = "3")]
    pub gossip_fanout: usize,

    #[clap(
        long,
        help = "Gossip max number of items an event is seen before \
retransmitting the event again.",
        default_value = "3"
    )]
    pub gossip_max_seen_count: u8,

    #[clap(
        long,
        help = "The interval at which to ping a node, in milliseconds.",
        default_value = "500"
    )]
    pub failure_detection_interval: u64,

    #[clap(
        short,
        long,
        help = "How much files to compact each time.",
        default_value = "2"
    )]
    pub compaction_factor: usize,

    #[clap(
        long,
        help = "Page cache size in bytes.",
        default_value = "1073741824"
    )]
    pub page_cache_size: usize,

    #[clap(
        long,
        help = "How much time (in microseconds) to delay the WAL sync.
0 means no delay, sync on every write.
Note that on many systems, the effective resolution of sleep delays is 10 \
            milliseconds, so test your system before setting this value.",
        default_value = "0"
    )]
    pub wal_sync_delay: u64,

    #[clap(
        long,
        help = "Call fdatasync on the WAL file after each write.",
        default_value = "false"
    )]
    pub wal_sync: bool,

    #[clap(
        long,
        help = "The minimum size of an sstable (in bytes) to calculate and \
            store its bloom filter.",
        default_value = "1048576"
    )]
    pub sstable_bloom_min_size: u64,

    #[clap(
        long,
        help = "Foreground tasks shares (0 - 1000).",
        default_value = "1000"
    )]
    pub foreground_tasks_shares: u16,

    #[clap(
        long,
        help = "Background tasks shares (0 - 1000).",
        default_value = "250"
    )]
    pub background_tasks_shares: u16,
}

#[must_use]
pub fn parse_args() -> Args {
    Args::parse()
}

pub fn parse_args_from<I, T>(itr: I) -> Args
where
    I: IntoIterator<Item = T>,
    T: Into<OsString> + Clone,
{
    Args::parse_from(itr)
}