This works on Linux, Android, Windows, macOS, FreeBSD, NetBSD, OpenBSD, DragonFlyBSD, Solaris and Illumos. Newly supported compared to the C version is Windows. Compared to the C version various error paths are handled more correctly and a couple of memory leaks are fixed. Otherwise it should work identically. The minimum required Rust version for compiling this is 1.48, i.e. the version currently in Debian stable. On Windows, Rust 1.54 is needed at least. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1259 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3889>
67 lines
1.6 KiB
Rust
67 lines
1.6 KiB
Rust
// GStreamer
|
|
//
|
|
// Copyright (C) 2015-2023 Sebastian Dröge <sebastian@centricular.com>
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
// <https://mozilla.org/MPL/2.0/>.
|
|
//
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
use std::env;
|
|
|
|
use crate::{
|
|
bail,
|
|
error::{Context, Error},
|
|
};
|
|
|
|
/// Parsed command-line arguments.
|
|
#[derive(Debug)]
|
|
pub struct Args {
|
|
pub interfaces: Vec<String>,
|
|
pub verbose: bool,
|
|
pub clock_id: u64,
|
|
}
|
|
|
|
/// Parse the command-line arguments.
|
|
pub fn parse_args() -> Result<Args, Error> {
|
|
let mut interfaces = Vec::new();
|
|
let mut verbose = false;
|
|
let mut clock_id = 0;
|
|
|
|
let mut args = env::args();
|
|
// Skip executable name
|
|
let _ = args.next();
|
|
|
|
while let Some(arg) = args.next() {
|
|
match arg.as_str() {
|
|
"-v" | "--verbose" => {
|
|
verbose = true;
|
|
}
|
|
"-i" | "--interface" => {
|
|
let iface = args.next().context("No interface following -i")?;
|
|
interfaces.push(iface);
|
|
}
|
|
"-c" | "--clock-id" => {
|
|
let clock_id_arg = args.next().context("No clock-id following -c")?;
|
|
clock_id = clock_id_arg.parse::<u64>().context("Invalid clock ID")?;
|
|
}
|
|
arg => {
|
|
bail!("Unknown command-line argument {}", arg);
|
|
}
|
|
}
|
|
}
|
|
|
|
let args = Args {
|
|
interfaces,
|
|
verbose,
|
|
clock_id,
|
|
};
|
|
|
|
if verbose {
|
|
eprintln!("Running with arguments {:#?}", args);
|
|
}
|
|
|
|
Ok(args)
|
|
}
|