Skip to content

Commit

Permalink
completions should work when server not running
Browse files Browse the repository at this point in the history
In neptune-cli:

  * process completions command before connecting to server.

In install-bash-completions.sh:

  * modify error handling so error on any line will abort script.
  • Loading branch information
dan-da authored and Sword-Smith committed Sep 25, 2023
1 parent 45e9d7a commit b9f172e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions scripts/install-bash-completions.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
set -e

SCRIPT="$HOME/.bash_neptune_cli"
LINE="source $SCRIPT"
FILE="$HOME/.bashrc"

cargo run --bin neptune-cli -- completions > $SCRIPT && \
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE" && \
source $SCRIPT && \
cargo run --bin neptune-cli -- completions > $SCRIPT
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
source $SCRIPT
echo "completions installed to $SCRIPT and added to $FILE"

19 changes: 12 additions & 7 deletions src/bin/neptune-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ struct Config {
#[tokio::main]
async fn main() -> Result<()> {
let args: Config = Config::parse();

// Check for completions command before establishing server connection.
if let Command::Completions = args.command {
if let Some(shell) = Shell::from_env() {
generate(shell, &mut Config::command(), "neptune-cli", &mut stdout());
return Ok(());
} else {
bail!("Unknown shell. Shell completions not available.")
}
}

let transport = tarpc::serde_transport::tcp::connect(args.server_addr, Json::default);
let client = RPCClient::new(client::Config::default(), transport.await?).spawn();

Expand Down Expand Up @@ -164,13 +175,7 @@ async fn main() -> Result<()> {
println!("{prunt_res_count} monitored UTXOs marked as abandoned");
}

Command::Completions => {
if let Some(shell) = Shell::from_env() {
generate(shell, &mut Config::command(), "neptune-cli", &mut stdout());
} else {
bail!("Unknown shell. Shell completions not available.")
}
}
Command::Completions => {} // handled before server connection.
}

Ok(())
Expand Down

0 comments on commit b9f172e

Please sign in to comment.