Skip to content

CLI Options

Configuration options for CLI commands and mock device behavior. Options controls serial port, baud rate, and output formatting, while MockOptions configures the mock device's event generation.


Options

kazunoko.options.Options

Centralized typer.Option definitions for device communication commands

Example
import typer
from kazunoko.options import Options

app = typer.Typer()

@app.command()
def status(port: str = Options.port(), verbose: bool = Options.verbose()):
    """Show device status"""
    # Command implementation
    pass

@app.command()
def read(
    event: int = typer.Argument(...),
    port: str = Options.port(),
    format: str = Options.format(),
):
    """Read detection events"""
    # Command implementation
    pass
Source code in src/kazunoko/options.py
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
class Options:
    """
    Centralized typer.Option definitions for device communication commands

    Example:
        ```python
        import typer
        from kazunoko.options import Options

        app = typer.Typer()

        @app.command()
        def status(port: str = Options.port(), verbose: bool = Options.verbose()):
            \"\"\"Show device status\"\"\"
            # Command implementation
            pass

        @app.command()
        def read(
            event: int = typer.Argument(...),
            port: str = Options.port(),
            format: str = Options.format(),
        ):
            \"\"\"Read detection events\"\"\"
            # Command implementation
            pass
        ```
    """

    # Connection options
    @staticmethod
    def port() -> str:
        """Serial port option (default: auto-detection)"""
        return typer.Option(
            "auto",
            "--port",
            "-p",
            help="Serial port or 'auto' for auto-detection",
        )

    @staticmethod
    def timeout(default: float = 0.1) -> float:
        """Serial communication timeout option (seconds)"""
        return typer.Option(
            default,
            "--timeout",
            "-t",
            help="Serial communication timeout in seconds (default: 0.1)",
        )

    @staticmethod
    def verbose() -> bool:
        """Verbose console output option (for user-facing status messages)"""
        return typer.Option(
            False,
            "--verbose/--quiet",
            "-v/-q",
            help="Show verbose status messages (--verbose) or suppress them (--quiet)",
        )

    # Output formatting options
    @staticmethod
    def format(
        default: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = "jsonl",
    ) -> Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"]:
        """Output format option (table, jsonl, json, csv, ssv, tsv, ltsv)"""
        return typer.Option(
            default,
            "--format",
            "-f",
            help="Output format: jsonl (default), table, json, csv, ssv, tsv, or ltsv",
        )

    @staticmethod
    def use_flat(default: bool = True) -> bool:
        """Flattened structure option"""
        return typer.Option(
            default,
            "--use-flat/--use-raw",
            help=(
                "Use flattened (True) or raw (False) structure "
                "(default: flattened for compact output)"
            ),
        )

    @staticmethod
    def use_event(default: bool = True) -> bool:
        """Event count vs duration option"""
        return typer.Option(
            default,
            "--use-event/--use-sec",
            help="Read/collect by event count (default) or by duration in seconds",
        )

    @staticmethod
    def event_timeout(default: float = 5.0) -> float:
        """Event reception timeout option (seconds)"""
        return typer.Option(
            default,
            "--event-timeout",
            "-et",
            help="Timeout in seconds to wait for an event before moving to next count (default: 5.0)",
        )

    @staticmethod
    def poll_count(default: int = 10) -> int:
        """Poll count option for device configuration"""
        return typer.Option(
            default,
            "--poll-count",
            "-pc",
            min=1,
            max=65535,
            help="Number of events to poll per cycle (range: 1-65535, default: 10)",
        )

    # Logging options
    @staticmethod
    def log_level(
        default: LogLevel = "error"
    ) -> LogLevel:
        """Logging level option (debug, info, success, warning, error)"""
        return typer.Option(
            default,
            "--log-level",
            help="Logging level: debug, info, success, warning, or error (default: error)",
        )

    @staticmethod
    def pattern(default: str) -> str:
        """Glob pattern option for filtering files"""
        return typer.Option(
            default,
            "--pattern",
            help="Glob pattern to filter files (e.g. '*.jsonl', '*.parquet', '*.root')",
        )

event_timeout(default=5.0) staticmethod

Event reception timeout option (seconds)

Source code in src/kazunoko/options.py
116
117
118
119
120
121
122
123
124
@staticmethod
def event_timeout(default: float = 5.0) -> float:
    """Event reception timeout option (seconds)"""
    return typer.Option(
        default,
        "--event-timeout",
        "-et",
        help="Timeout in seconds to wait for an event before moving to next count (default: 5.0)",
    )

format(default='jsonl') staticmethod

Output format option (table, jsonl, json, csv, ssv, tsv, ltsv)

Source code in src/kazunoko/options.py
83
84
85
86
87
88
89
90
91
92
93
@staticmethod
def format(
    default: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = "jsonl",
) -> Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"]:
    """Output format option (table, jsonl, json, csv, ssv, tsv, ltsv)"""
    return typer.Option(
        default,
        "--format",
        "-f",
        help="Output format: jsonl (default), table, json, csv, ssv, tsv, or ltsv",
    )

log_level(default='error') staticmethod

Logging level option (debug, info, success, warning, error)

Source code in src/kazunoko/options.py
139
140
141
142
143
144
145
146
147
148
@staticmethod
def log_level(
    default: LogLevel = "error"
) -> LogLevel:
    """Logging level option (debug, info, success, warning, error)"""
    return typer.Option(
        default,
        "--log-level",
        help="Logging level: debug, info, success, warning, or error (default: error)",
    )

pattern(default) staticmethod

Glob pattern option for filtering files

Source code in src/kazunoko/options.py
150
151
152
153
154
155
156
157
@staticmethod
def pattern(default: str) -> str:
    """Glob pattern option for filtering files"""
    return typer.Option(
        default,
        "--pattern",
        help="Glob pattern to filter files (e.g. '*.jsonl', '*.parquet', '*.root')",
    )

poll_count(default=10) staticmethod

Poll count option for device configuration

Source code in src/kazunoko/options.py
126
127
128
129
130
131
132
133
134
135
136
@staticmethod
def poll_count(default: int = 10) -> int:
    """Poll count option for device configuration"""
    return typer.Option(
        default,
        "--poll-count",
        "-pc",
        min=1,
        max=65535,
        help="Number of events to poll per cycle (range: 1-65535, default: 10)",
    )

port() staticmethod

Serial port option (default: auto-detection)

Source code in src/kazunoko/options.py
52
53
54
55
56
57
58
59
60
@staticmethod
def port() -> str:
    """Serial port option (default: auto-detection)"""
    return typer.Option(
        "auto",
        "--port",
        "-p",
        help="Serial port or 'auto' for auto-detection",
    )

timeout(default=0.1) staticmethod

Serial communication timeout option (seconds)

Source code in src/kazunoko/options.py
62
63
64
65
66
67
68
69
70
@staticmethod
def timeout(default: float = 0.1) -> float:
    """Serial communication timeout option (seconds)"""
    return typer.Option(
        default,
        "--timeout",
        "-t",
        help="Serial communication timeout in seconds (default: 0.1)",
    )

use_event(default=True) staticmethod

Event count vs duration option

Source code in src/kazunoko/options.py
107
108
109
110
111
112
113
114
@staticmethod
def use_event(default: bool = True) -> bool:
    """Event count vs duration option"""
    return typer.Option(
        default,
        "--use-event/--use-sec",
        help="Read/collect by event count (default) or by duration in seconds",
    )

use_flat(default=True) staticmethod

Flattened structure option

Source code in src/kazunoko/options.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
@staticmethod
def use_flat(default: bool = True) -> bool:
    """Flattened structure option"""
    return typer.Option(
        default,
        "--use-flat/--use-raw",
        help=(
            "Use flattened (True) or raw (False) structure "
            "(default: flattened for compact output)"
        ),
    )

verbose() staticmethod

Verbose console output option (for user-facing status messages)

Source code in src/kazunoko/options.py
72
73
74
75
76
77
78
79
80
@staticmethod
def verbose() -> bool:
    """Verbose console output option (for user-facing status messages)"""
    return typer.Option(
        False,
        "--verbose/--quiet",
        "-v/-q",
        help="Show verbose status messages (--verbose) or suppress them (--quiet)",
    )

MockOptions

kazunoko.options.MockOptions

Centralized typer.Option definitions for mock device and testing

Example
import typer
from kazunoko.options import MockOptions

app = typer.Typer()

@app.command()
def generate(
    count: int = MockOptions.generate_count(),
    speed: float = MockOptions.speed(),
    jitter: float = MockOptions.jitter(),
    seed: int | None = MockOptions.seed(),
):
    """Generate mock detection events"""
    # Command implementation
    pass
Source code in src/kazunoko/options.py
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
class MockOptions:
    """
    Centralized typer.Option definitions for mock device and testing

    Example:
        ```python
        import typer
        from kazunoko.options import MockOptions

        app = typer.Typer()

        @app.command()
        def generate(
            count: int = MockOptions.generate_count(),
            speed: float = MockOptions.speed(),
            jitter: float = MockOptions.jitter(),
            seed: int | None = MockOptions.seed(),
        ):
            \"\"\"Generate mock detection events\"\"\"
            # Command implementation
            pass
        ```
    """

    @staticmethod
    def mock() -> bool:
        """Mock device option for testing"""
        return typer.Option(
            False, "--mock", help="Use mock device for testing"
        )

    # Event generation options
    @staticmethod
    def generate_count() -> int:
        """Count option for generate command"""
        return typer.Option(
            10, "--count", "-c", help="Number of events to generate"
        )

    @staticmethod
    def speed() -> float:
        """Event generation speed option (0.01-100x)"""
        return typer.Option(
            1.0, "--speed", "-s", help="Event generation speed (0.01-100x)"
        )

    @staticmethod
    def jitter() -> float:
        """Event timing jitter option"""
        return typer.Option(
            0.0, "--jitter", "-j", help="Event timing jitter (seconds)"
        )

    @staticmethod
    def seed() -> int | None:
        """Random seed option for reproducibility"""
        return typer.Option(
            None, help="Random seed for reproducibility"
        )

generate_count() staticmethod

Count option for generate command

Source code in src/kazunoko/options.py
192
193
194
195
196
197
@staticmethod
def generate_count() -> int:
    """Count option for generate command"""
    return typer.Option(
        10, "--count", "-c", help="Number of events to generate"
    )

jitter() staticmethod

Event timing jitter option

Source code in src/kazunoko/options.py
206
207
208
209
210
211
@staticmethod
def jitter() -> float:
    """Event timing jitter option"""
    return typer.Option(
        0.0, "--jitter", "-j", help="Event timing jitter (seconds)"
    )

mock() staticmethod

Mock device option for testing

Source code in src/kazunoko/options.py
184
185
186
187
188
189
@staticmethod
def mock() -> bool:
    """Mock device option for testing"""
    return typer.Option(
        False, "--mock", help="Use mock device for testing"
    )

seed() staticmethod

Random seed option for reproducibility

Source code in src/kazunoko/options.py
213
214
215
216
217
218
@staticmethod
def seed() -> int | None:
    """Random seed option for reproducibility"""
    return typer.Option(
        None, help="Random seed for reproducibility"
    )

speed() staticmethod

Event generation speed option (0.01-100x)

Source code in src/kazunoko/options.py
199
200
201
202
203
204
@staticmethod
def speed() -> float:
    """Event generation speed option (0.01-100x)"""
    return typer.Option(
        1.0, "--speed", "-s", help="Event generation speed (0.01-100x)"
    )