• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polyphony-chat / sonata / 15807535527

22 Jun 2025 02:19PM UTC coverage: 95.556% (+26.5%) from 69.048%
15807535527

push

github

web-flow
Merge pull request #1 from polyphony-chat/flori/test-nightly-coverage-off

feat(test): run coverage on nightly, use coverage(off) to ignore code

172 of 180 relevant lines covered (95.56%)

2.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/cli/mod.rs
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4

5
use std::path::PathBuf;
6
use std::sync::OnceLock;
7

8
use clap::Parser;
9

10
use crate::StdResult;
11

12
static CLI_ARGUMENTS: OnceLock<Args> = OnceLock::new();
13

14
#[derive(Debug, clap::Parser)]
15
#[command(name = "sonata")]
16
#[command(version, long_about = None)]
17
pub struct Args {
18
    #[arg(short, long, value_name = "FILE")]
19
    /// Path to a sonata config.toml file. If not specified, will use default values.
20
    pub(crate) config: Option<PathBuf>,
21

22
    #[arg(short = 'v', long, action = clap::ArgAction::Count)]
23
    /// Turn on verbose logging. The default log level is "INFO".
24
    /// Each instance of "v" in "-v" will increase the logging level by one. Logging levels are
25
    /// DEBUG (-v) and TRACE (-vv).
26
    /// "Quiet" settings override "verbose" settings. If set, overrides config value.
27
    pub(crate) verbose: u8,
28
    #[arg(short = 'q', long, action = clap::ArgAction::Count)]
29
    /// Configure "quiet" mode. The default log level is "INFO".
30
    /// Each instance of "q" in "-q" will decrease the logging level by one. Logging levels are
31
    /// WARN (-q), ERROR (-qq) and None (completely silent, except for regular stdout) (-qqq).
32
    /// "Quiet" settings override "verbose" settings. If set, overrides config value.
33
    pub(crate) quiet: u8,
34
}
35

36
impl Args {
37
    pub fn init_global() -> StdResult<&'static Self> {
×
38
        let parsed = Args::try_parse()?;
×
39
        CLI_ARGUMENTS.set(parsed).map_err(|_| String::from("cli arguments already parsed"))?;
×
40
        Ok(CLI_ARGUMENTS.get().ok_or("cli arguments not set? this should never happen")?)
×
41
    }
×
42

43
    /// Get a reference to the parsed CLI args. Will panic, if the CLI args have not been parsed using
44
    /// `Self::init()` prior to calling this function.
45
    #[allow(clippy::expect_used)]
46
    pub fn get_or_panic() -> &'static Self {
1✔
47
        CLI_ARGUMENTS.get().expect("cli arguments should have been set")
1✔
48
    }
1✔
49
}
50

51
#[cfg(test)]
52
mod tests {
53
    use super::*;
54

55
    #[test]
56
    #[should_panic(expected = "cli arguments should have been set")]
57
    fn test_get_or_panic_without_init() {
1✔
58
        // This test should panic because CLI_ARGUMENTS hasn't been initialized
59
        // Note: This test might fail if run after other tests that initialize CLI_ARGUMENTS
60
        Args::get_or_panic();
1✔
61
    }
1✔
62

63
    // Note: Testing init_global() and command line parsing would require
64
    // either mocking or integration tests, as they interact with global state
65
    // and command line arguments
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc