rust_unique_pass/cli/
cli.rs

1use clap::Parser;
2
3/// # Overview
4/// コマンドライン引数を定義する構造体。
5/// `clap` クレートを使用して引数をパースします。
6#[derive(Parser, Debug, PartialEq)]
7pub struct RupassArgs {
8    // 設定言語を指定する
9    #[clap(
10        short = 'l',
11        long = "language",
12        value_name = "LANGUAGE",
13        help = "Specifies the language for user prompts and messages.\
14            \nSpecify the language code as defined by ISO639-3.\
15            \nSupported languages: Japanese, English, and German.\
16            \nDefault language: English"
17    )]
18    pub language: Option<String>,
19
20    // パスワード長を指定する
21    #[clap(
22        short = 'p',
23        long = "password-length",
24        value_name = "PASSWORD_LENGTH",
25        help = "Specify the length of the password. \
26            \nIf omitted, a default length is used."
27    )]
28    pub password_length: Option<usize>,
29
30    // 数字を含むかどうかのフラグ
31    #[clap(
32        short = 'n',
33        long = "numbers",
34        help = "Include numbers in the password."
35    )]
36    pub numbers: bool,
37
38    // 大文字を含むかどうかのフラグ
39    #[clap(
40        short = 'u',
41        long = "uppercase",
42        help = "Include uppercase letters in the password."
43    )]
44    pub uppercase: bool,
45
46    // 小文字を含むかどうかのフラグ
47    #[clap(
48        short = 'w',
49        long = "lowercase",
50        help = "Include lowercase letters in the password."
51    )]
52    pub lowercase: bool,
53
54    // 特殊記号を含むかどうかのフラグ
55    #[clap(
56        short = 's',
57        long = "symbols",
58        help = "Include symbols in passwords.\
59        \nBy default, the symbols ~!@#$%^&*_-+=(){}[]:;<>,.?/ are used.\
60        \nYou can change which special symbols are used."
61    )]
62    pub symbols: bool,
63}
64
65/// # Overview
66/// コマンドライン引数をパースして [`RupassArgs`] 構造体を生成します。
67/// `clap::Parser::parse()` を使用します。
68#[doc(alias = "parse")]
69#[doc(alias = "args")]
70pub fn parse_args() -> RupassArgs {
71    RupassArgs::parse()
72}