flareapp-core 0.2.0

The core of the Flare client: config, the client, and the worker thread that sends data.
Documentation
//! The command line this process was started with.

use std::env;
use std::sync::OnceLock;

/// Returns the arguments this process was started with, starting with the
/// program.
///
/// Arguments that are not valid UTF-8 get replacement characters. `env::args()`
/// panics on them, and the Flare client must never crash the app.
pub fn command_args() -> &'static [String] {
    static ARGS: OnceLock<Vec<String>> = OnceLock::new();

    ARGS.get_or_init(|| {
        env::args_os()
            .map(|argument| argument.to_string_lossy().into_owned())
            .collect()
    })
}

/// Returns the file name of this process's executable, like `my-app`, or
/// `my-app.exe` on Windows. OpenTelemetry calls it `process.executable.name`.
/// Returns `None` when the operating system does not tell.
///
/// Used by the Flare integrations. Not part of the public API.
pub fn executable_name() -> Option<&'static str> {
    static NAME: OnceLock<Option<String>> = OnceLock::new();

    NAME.get_or_init(|| {
        let executable = env::current_exe().ok()?;
        let name = executable.file_name()?;

        Some(name.to_string_lossy().into_owned())
    })
    .as_deref()
}

/// Returns the command line of this process: the arguments joined by spaces.
pub fn command_line() -> &'static str {
    static LINE: OnceLock<String> = OnceLock::new();

    LINE.get_or_init(|| command_args().join(" "))
}