1
// This file is part of hnefatafl-copenhagen.
2
//
3
// hnefatafl-copenhagen is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU Affero General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// hnefatafl-copenhagen is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU Affero General Public License for more details.
12
//
13
// You should have received a copy of the GNU Affero General Public License
14
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
//
16
// SPDX-License-Identifier: AGPL-3.0-or-later
17
// SPDX-FileCopyrightText: 2025 David Campbell <david@hnefatafl.org>
18

            
19
use std::io::Write as _;
20

            
21
use clap::{CommandFactory, Parser};
22
use hnefatafl_copenhagen::{COPYRIGHT, LONG_VERSION};
23

            
24
/// Copenhagen Hnefatafl Server
25
///
26
/// This is a TCP server that listens for client connections.
27
#[allow(clippy::struct_excessive_bools)]
28
#[derive(Parser, Debug)]
29
#[command(long_version = LONG_VERSION, about = "Copenhagen Hnefatafl Server")]
30
pub(crate) struct Args {
31
    /// Whether to automatically start a tournament
32
    #[arg(long)]
33
    pub autostart_tournament: bool,
34

            
35
    /// Whether to log on the debug level
36
    #[arg(long)]
37
    pub debug: bool,
38

            
39
    /// Whether to skip advertising updates
40
    #[arg(long)]
41
    pub skip_advertising_updates: bool,
42

            
43
    /// Whether to skip the data file
44
    #[arg(long)]
45
    pub skip_the_data_file: bool,
46

            
47
    /// Whether the application is being run by systemd
48
    #[arg(long)]
49
    pub systemd: bool,
50

            
51
    /// Add additional security checks
52
    ///
53
    /// - limit the number of TCP connections from a host
54
    #[arg(long)]
55
    pub secure: bool,
56

            
57
    /// The size of the tournament groups
58
    #[arg(default_value_t = 4, long)]
59
    pub group_size: usize,
60

            
61
    /// Build the manpage
62
    #[arg(long)]
63
    pub man: bool,
64
}
65

            
66
impl Args {
67
    pub(crate) fn generate_man_page() -> anyhow::Result<()> {
68
        let mut buffer: Vec<u8> = Vec::default();
69
        let cmd = Self::command()
70
            .name("hnefatafl-server-full")
71
            .long_version(None);
72
        let man = clap_mangen::Man::new(cmd).date("2025-06-23");
73

            
74
        man.render(&mut buffer)?;
75
        write!(buffer, "{COPYRIGHT}")?;
76

            
77
        std::fs::write("hnefatafl-server-full.1", buffer)?;
78
        Ok(())
79
    }
80
}