use std::{path::PathBuf, process::Command};
use crate::{utils, QtInstallation, QtTool};
#[derive(Default)]
pub struct QtPathsQueryArguments {
query: Option<String>,
qtconf: Option<String>,
}
impl QtPathsQueryArguments {
pub fn query(mut self, query: &str) -> Self {
self.query = Some(query.to_string());
self
}
pub fn qtconf(mut self, qtconf: &str) -> Self {
self.qtconf = Some(qtconf.to_string());
self
}
}
impl From<&str> for QtPathsQueryArguments {
fn from(value: &str) -> Self {
Self::default().query(value)
}
}
pub struct QtToolQtPaths {
executable: PathBuf,
}
impl QtToolQtPaths {
pub fn new(qt_installation: &dyn QtInstallation) -> Self {
let executable = qt_installation
.try_find_tool(QtTool::QtPaths)
.expect("Could not find qtpaths");
utils::check_executable_help(&executable).unwrap();
Self { executable }
}
pub fn query(&self, query_args: impl Into<QtPathsQueryArguments>) -> Option<String> {
let query_args = query_args.into();
let mut args = vec![];
if let Some(query) = &query_args.query {
args.extend(["--query", query]);
} else {
args.push("--query")
}
if let Some(qtconf) = &query_args.qtconf {
args.extend(["--qtconf", qtconf]);
}
let output = Command::new(&self.executable)
.args(args)
.env_clear()
.output()
.ok()?
.stdout;
Some(String::from_utf8_lossy(&output).trim().to_owned())
}
}
#[cfg(feature = "qt_minimal")]
impl QtToolQtPaths {
pub(crate) fn from_path_buf(executable: PathBuf) -> Self {
utils::check_executable_help(&executable).unwrap();
Self { executable }
}
}