Skip to content

Commit

Permalink
feat: use stellar_xdr::cli at top level xdr
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Dec 5, 2023
1 parent bee1f45 commit dd22eb0
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 9 deletions.
33 changes: 25 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ soroban-spec-typescript = { workspace = true }
soroban-ledger-snapshot = { workspace = true }
stellar-strkey = { workspace = true }
soroban-sdk = { workspace = true }

clap = { version = "4.1.8", features = [
"derive",
"env",
Expand All @@ -69,7 +70,7 @@ csv = "1.1.6"
ed25519-dalek = "2.0.0"
jsonrpsee-http-client = "0.20.1"
jsonrpsee-core = "0.20.1"
hyper = "0.14.27"
hyper = "0.14.27"
hyper-tls = "0.5"
http = "0.2.9"
regex = "1.6.0"
Expand All @@ -92,6 +93,13 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] }
cargo_metadata = "0.15.4"
pathdiff = "0.2.1"
dotenvy = "0.15.7"

[dependencies.stellar-xdr]
version = "20.0.0-rc1"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "5dcb7a4549a2901e4040641710c5fdef5cbd526d"
features = ["cli"]

# For hyper-tls
[target.'cfg(unix)'.dependencies]
openssl = { version = "0.10.55", features = ["vendored"] }
Expand Down
9 changes: 9 additions & 0 deletions cmd/soroban-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod keys;
pub mod network;
pub mod plugin;
pub mod version;
pub mod xdr;

pub const HEADING_RPC: &str = "Options (RPC)";
const ABOUT: &str = "Build, deploy, & interact with contracts; set identities to sign with; configure networks; generate keys; and more.
Expand Down Expand Up @@ -61,6 +62,7 @@ pub struct Root {

impl Root {
pub fn new() -> Result<Self, Error> {
xdr::try_cmd()?;
Self::try_parse().map_err(|e| {
if std::env::args().any(|s| s == "--list") {
let plugins = plugin::list().unwrap_or_default();
Expand Down Expand Up @@ -96,6 +98,9 @@ impl Root {
Cmd::Network(network) => network.run()?,
Cmd::Version(version) => version.run(),
Cmd::Keys(id) => id.run().await?,
// This is never actually run because we handle it in `new` above
// It is here to satisfy the help generator which uses the enum
Cmd::Xdr(lab) => lab.run()?,
};
Ok(())
}
Expand Down Expand Up @@ -127,6 +132,8 @@ pub enum Cmd {
Network(network::Cmd),
/// Print version information
Version(version::Cmd),
/// Encode and Decode XDR values
Xdr(xdr::Cmd),
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -146,4 +153,6 @@ pub enum Error {
Plugin(#[from] plugin::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
}
28 changes: 28 additions & 0 deletions cmd/soroban-cli/src/commands/xdr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use clap::Parser;
use std::ffi::OsString;
use stellar_xdr::cli;

pub use cli::Error;

#[derive(Parser, Debug)]
pub struct Cmd {
pub slop: Vec<OsString>,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
cli::run(&self.slop)
}
}

pub fn try_cmd() -> Result<(), Error> {
let mut args = std::env::args().peekable();
args.next().unwrap();
if let Some(s) = args.peek() {
if s == "xdr" {
stellar_xdr::cli::run(args)?;
std::process::exit(0);
}
}
Ok(())
}
14 changes: 14 additions & 0 deletions docs/soroban-cli-full-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This document contains the help content for the `soroban` command-line program.
* [`soroban network rm`](#soroban-network-rm)
* [`soroban network ls`](#soroban-network-ls)
* [`soroban version`](#soroban-version)
* [`soroban xdr`](#soroban-xdr)

## `soroban`

Expand Down Expand Up @@ -78,6 +79,7 @@ Full CLI reference: https://github.com/stellar/soroban-tools/tree/main/docs/soro
* `keys` — Create and manage identities including keys and addresses
* `network` — Start and configure networks
* `version` — Print version information
* `xdr` — Encode and Decode XDR values

###### **Options:**

Expand Down Expand Up @@ -831,6 +833,18 @@ Print version information



## `soroban xdr`

Encode and Decode XDR values

**Usage:** `soroban xdr [SLOP]...`

###### **Arguments:**

* `<SLOP>`



<hr/>

<small><i>
Expand Down

0 comments on commit dd22eb0

Please sign in to comment.