cli/node/status: Add `--only nid`
This commit is contained in:
parent
8afd55ff6f
commit
2635562c92
|
|
@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `rad init --setup-signing` now works on bare repositories.
|
||||
- `git-remote-rad` now correctly reports the default branch to Git by listing
|
||||
the symbolic reference `HEAD`.
|
||||
- `rad status` learned a new option `--only nid` for printing the Node ID.
|
||||
|
||||
## Fixed Bugs
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
|||
|
||||
```
|
||||
$ rad self --nid
|
||||
! Warning: The option `--nid` is deprecated, please use `rad node status` instead.
|
||||
! Warning: The option `--nid` is deprecated, please use `rad node status --only nid` instead.
|
||||
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time;
|
||||
use std::{process, time};
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
||||
|
|
@ -64,6 +64,11 @@ Events options
|
|||
--timeout <secs> How long to wait to receive an event before giving up
|
||||
--count, -n <count> Exit after <count> events
|
||||
|
||||
Status options
|
||||
|
||||
--only nid If node is running, only print the Node ID and exit,
|
||||
otherwise exit with a non-zero exit status.
|
||||
|
||||
General options
|
||||
|
||||
--help Print help
|
||||
|
|
@ -127,7 +132,9 @@ pub enum Operation {
|
|||
Logs {
|
||||
lines: usize,
|
||||
},
|
||||
Status,
|
||||
Status {
|
||||
only_nid: bool,
|
||||
},
|
||||
Inventory {
|
||||
nid: Option<NodeId>,
|
||||
},
|
||||
|
|
@ -171,6 +178,7 @@ impl Args for Options {
|
|||
let mut addresses = false;
|
||||
let mut path = None;
|
||||
let mut verbose = false;
|
||||
let mut only_nid = false;
|
||||
|
||||
while let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
|
|
@ -207,6 +215,13 @@ impl Args for Options {
|
|||
let val = parser.value()?;
|
||||
nid = term::args::nid(&val).ok();
|
||||
}
|
||||
Long("only") if matches!(op, Some(OperationName::Status)) => {
|
||||
if &parser.value()? == "nid" {
|
||||
only_nid = true;
|
||||
} else {
|
||||
anyhow::bail!("unknown argument to --only");
|
||||
}
|
||||
}
|
||||
Long("json") if matches!(op, Some(OperationName::Routing)) => json = true,
|
||||
Long("timeout")
|
||||
if op == Some(OperationName::Events) || op == Some(OperationName::Connect) =>
|
||||
|
|
@ -263,7 +278,7 @@ impl Args for Options {
|
|||
path: path.unwrap_or(PathBuf::from("radicle-node")),
|
||||
},
|
||||
OperationName::Inventory => Operation::Inventory { nid },
|
||||
OperationName::Status => Operation::Status,
|
||||
OperationName::Status => Operation::Status { only_nid },
|
||||
OperationName::Debug => Operation::Debug,
|
||||
OperationName::Sessions => Operation::Sessions,
|
||||
OperationName::Stop => Operation::Stop,
|
||||
|
|
@ -333,9 +348,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|||
println!("{}", term::format::tertiary(rid));
|
||||
}
|
||||
}
|
||||
Operation::Status => {
|
||||
Operation::Status { only_nid: false } => {
|
||||
control::status(&node, &profile)?;
|
||||
}
|
||||
Operation::Status { only_nid: true } => {
|
||||
if node.is_running() {
|
||||
term::print(term::format::node_id_human(&node.nid()?));
|
||||
} else {
|
||||
process::exit(2);
|
||||
}
|
||||
}
|
||||
Operation::Stop => {
|
||||
control::stop(node, &profile);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|||
}
|
||||
Show::NodeId => {
|
||||
term::warning(
|
||||
"The option `--nid` is deprecated, please use `rad node status` instead.",
|
||||
"The option `--nid` is deprecated, please use `rad node status --only nid` instead.",
|
||||
);
|
||||
term::print(
|
||||
Node::new(profile.socket())
|
||||
|
|
|
|||
Loading…
Reference in New Issue