Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge rust client lib in
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmittag committed Nov 15, 2023
2 parents 9629dde + 2e0fd06 commit b9001b4
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions kuksa_databroker/databroker-cli/src/sdv_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ fn print_usage(command: impl AsRef<str>) {
}
}

pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
let mut _properties = Vec::<proto::v1::Metadata>::new();
pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
let mut properties = Vec::<proto::v1::Metadata>::new();
println!("Using {VERSION}");
let mut cli = _cli;

Expand Down Expand Up @@ -162,6 +162,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
Ok(metadata) => {
interface
.set_completer(Arc::new(CliCompleter::from_metadata(&metadata)));
properties = metadata;
}
Err(common::ClientError::Status(status)) => {
cli::print_resp_err("metadata", &status)?;
Expand Down Expand Up @@ -240,7 +241,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
interface.set_completer(Arc::new(
CliCompleter::from_metadata(&metadata),
));
_properties = metadata;
properties = metadata;
}
Err(common::ClientError::Status(status)) => {
cli::print_resp_err("metadata", &status)?;
Expand Down Expand Up @@ -277,7 +278,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
interface.set_completer(Arc::new(
CliCompleter::from_metadata(&metadata),
));
_properties = metadata;
properties = metadata;
}
Err(common::ClientError::Status(status)) => {
cli::print_resp_err("metadata", &status)?;
Expand Down Expand Up @@ -318,7 +319,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{

let datapoint_metadata = {
let mut datapoint_metadata = None;
for metadata in _properties.iter() {
for metadata in properties.iter() {
if metadata.name == path {
datapoint_metadata = Some(metadata)
}
Expand Down Expand Up @@ -421,7 +422,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{

let datapoint_metadata = {
let mut datapoint_metadata = None;
for metadata in _properties.iter() {
for metadata in properties.iter() {
if metadata.name == path {
datapoint_metadata = Some(metadata)
}
Expand Down Expand Up @@ -645,7 +646,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
interface.set_completer(Arc::new(
CliCompleter::from_metadata(&metadata),
));
_properties = metadata;
properties = metadata;
}
Err(common::ClientError::Status(status)) => {
cli::print_resp_err("metadata", &status)?;
Expand All @@ -669,10 +670,10 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
match client.get_metadata(vec![]).await {
Ok(mut metadata) => {
metadata.sort_by(|a, b| a.name.cmp(&b.name));
_properties = metadata;
interface.set_completer(Arc::new(
CliCompleter::from_metadata(&_properties),
));
properties = metadata;
interface.set_completer(Arc::new(CliCompleter::from_metadata(
&properties,
)));
cli::print_resp_ok(cmd)?;
}
Err(common::ClientError::Status(status)) => {
Expand All @@ -691,12 +692,12 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box<dyn std::error::Error>>{
let mut filtered_metadata = Vec::new();
if paths.is_empty() {
cli::print_info("If you want to list metadata of signals, use `metadata PATTERN`")?;
// filtered_metadata.extend(&_properties);
// filtered_metadata.extend(&properties);
} else {
for path in &paths {
let path_re = path_to_regex(path);
let filtered =
_properties.iter().filter(|item| match &path_re {
properties.iter().filter(|item| match &path_re {
Ok(re) => re.is_match(&item.name),
Err(err) => {
cli::print_info(format!("Invalid path: {err}"))
Expand Down

0 comments on commit b9001b4

Please sign in to comment.