forked from eclipse-iceoryx/iceoryx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse-iceoryx#98] Implement
iox2 nodes list
- Loading branch information
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "iox2-nodes" | ||
description = "CLI for managing iceoryx2 nodes" | ||
categories = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
keywords = { workspace = true } | ||
license = { workspace = true } | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
version = { workspace = true } | ||
|
||
[dependencies] | ||
iceoryx2 = { workspace = true } | ||
iceoryx2-bb-log = { workspace = true } | ||
iceoryx2-cli-utils = { workspace = true } | ||
|
||
anyhow = { workspace = true } | ||
better-panic = { workspace = true } | ||
clap = { workspace = true } | ||
human-panic = { workspace = true } | ||
serde = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache Software License 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license | ||
// which is available at https://opensource.org/licenses/MIT. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use clap::Parser; | ||
use clap::Subcommand; | ||
|
||
use iceoryx2_cli_utils::help_template; | ||
use iceoryx2_cli_utils::Format; | ||
|
||
#[derive(Parser)] | ||
#[command( | ||
name = "iox2-nodes", | ||
about = "Query information about iceoryx2 nodes", | ||
long_about = None, | ||
version = env!("CARGO_PKG_VERSION"), | ||
disable_help_subcommand = true, | ||
arg_required_else_help = false, | ||
help_template = help_template("iox2-nodes", false), | ||
)] | ||
pub struct Cli { | ||
#[clap(subcommand)] | ||
pub action: Option<Action>, | ||
|
||
#[clap(long, short = 'f', value_enum, global = true)] | ||
pub format: Option<Format>, | ||
} | ||
|
||
#[derive(Parser)] | ||
pub struct DetailsOptions { | ||
#[clap(help = "")] | ||
pub node: String, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum Action { | ||
#[clap(about = "")] | ||
List, | ||
#[clap(about = "")] | ||
Details(DetailsOptions), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache Software License 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license | ||
// which is available at https://opensource.org/licenses/MIT. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
use anyhow::{Context, Result}; | ||
use iceoryx2::prelude::*; | ||
use iceoryx2_cli_utils::output::NodeDescriptor; | ||
use iceoryx2_cli_utils::output::NodeList; | ||
use iceoryx2_cli_utils::Format; | ||
|
||
pub fn list(format: Format) -> Result<()> { | ||
let mut nodes = Vec::<NodeDescriptor>::new(); | ||
Node::<ipc::Service>::list(Config::global_config(), |node_state| { | ||
nodes.push(NodeDescriptor::from(&node_state)); | ||
CallbackProgression::Continue | ||
}) | ||
.context("failed to retrieve nodes")?; | ||
|
||
print!( | ||
"{}", | ||
format.as_string(&NodeList { | ||
num: nodes.len(), | ||
details: nodes | ||
})? | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache Software License 2.0 which is available at | ||
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license | ||
// which is available at https://opensource.org/licenses/MIT. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
mod cli; | ||
mod commands; | ||
|
||
use clap::CommandFactory; | ||
use clap::Parser; | ||
use cli::Cli; | ||
use iceoryx2_bb_log::{set_log_level, LogLevel}; | ||
use iceoryx2_cli_utils::Format; | ||
|
||
#[cfg(not(debug_assertions))] | ||
use human_panic::setup_panic; | ||
#[cfg(debug_assertions)] | ||
extern crate better_panic; | ||
|
||
fn main() { | ||
#[cfg(not(debug_assertions))] | ||
{ | ||
setup_panic!(); | ||
} | ||
#[cfg(debug_assertions)] | ||
{ | ||
better_panic::Settings::debug() | ||
.most_recent_first(false) | ||
.lineno_suffix(true) | ||
.verbosity(better_panic::Verbosity::Full) | ||
.install(); | ||
} | ||
|
||
set_log_level(LogLevel::Warn); | ||
|
||
match Cli::try_parse() { | ||
Ok(cli) => { | ||
if let Some(action) = cli.action { | ||
match action { | ||
cli::Action::List => { | ||
if let Err(e) = commands::list(cli.format.unwrap_or(Format::Ron)) { | ||
eprintln!("Failed to list nodes: {}", e); | ||
} | ||
} | ||
cli::Action::Details(_) => todo!(), | ||
} | ||
} else { | ||
Cli::command().print_help().expect("Failed to print help"); | ||
} | ||
} | ||
Err(e) => { | ||
eprintln!("{}", e); | ||
} | ||
} | ||
} |