use http_body_util::Empty;
use hyper::body::Bytes;
use url::form_urlencoded;
use crate::{
client::Client,
models::{
connection::SendRequestOptions,
lib::Error,
podman::containers::list_processes::{
ContainerListProcesses, ContainerListProcessesOptions,
},
},
utils::bool_to_str::bool_to_str,
};
impl Client {
pub async fn container_list_processes(
&self,
options: ContainerListProcessesOptions<'_>,
) -> Result<ContainerListProcesses, Error> {
let mut path = ["/libpod/containers/", options.name, "/top"].concat();
let mut query = form_urlencoded::Serializer::new(String::new());
if let Some(delay) = options.delay {
query.append_pair("delay", itoa::Buffer::new().format(delay));
}
if let Some(ps_args) = options.ps_args {
for ps_arg in ps_args {
query.append_pair("ps_args", ps_arg);
}
}
if let Some(stream) = options.stream {
query.append_pair("stream", bool_to_str(stream));
}
let query_string = query.finish();
if !query_string.is_empty() {
path += &["?", &query_string].concat();
}
let (_, data) = self
.send_request::<_, (), _>(SendRequestOptions {
method: "GET",
path: &path,
header: None,
body: Empty::<Bytes>::new(),
})
.await?;
Ok(data)
}
}