Skip to content

Commit

Permalink
feat: include jsonrpc version in verbose version
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Aug 13, 2023
1 parent 8a74c91 commit 00585c1
Showing 1 changed file with 62 additions and 32 deletions.
94 changes: 62 additions & 32 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use clap::{CommandFactory, Parser, Subcommand};
use colored::Colorize;

use crate::{provider::ProviderArgs, subcommands::*};
Expand All @@ -20,12 +20,27 @@ mod utils;
mod verbosity;

const VERSION_STRING: &str = concat!(env!("CARGO_PKG_VERSION"), " (", env!("VERGEN_GIT_SHA"), ")");
const VERSION_STRING_VERBOSE: &str = concat!(
env!("CARGO_PKG_VERSION"),
" (",
env!("VERGEN_GIT_SHA"),
")\n",
"JSON-RPC version: 0.3.0"
);

#[derive(Debug, Parser)]
#[clap(author, version, about, version = VERSION_STRING)]
#[clap(author, about)]
struct Cli {
#[clap(subcommand)]
command: Subcommands,
command: Option<Subcommands>,
#[clap(long = "version", short = 'V', help = "Print version info and exit")]
version: bool,
#[clap(
long = "verbose",
short = 'v',
help = "Use verbose output (currently only applied to version)"
)]
verbose: bool,
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -122,34 +137,49 @@ async fn main() {
}

async fn run_command(cli: Cli) -> Result<()> {
match cli.command {
Subcommands::Selector(cmd) => cmd.run(),
Subcommands::ClassHash(cmd) => cmd.run(),
Subcommands::ToCairoString(cmd) => cmd.run(),
Subcommands::ParseCairoString(cmd) => cmd.run(),
Subcommands::Mont(cmd) => cmd.run(),
Subcommands::Call(cmd) => cmd.run().await,
Subcommands::Transaction(cmd) => cmd.run().await,
Subcommands::BlockNumber(cmd) => cmd.run().await,
Subcommands::BlockHash(cmd) => cmd.run().await,
Subcommands::Block(cmd) => cmd.run().await,
Subcommands::BlockTime(cmd) => cmd.run().await,
Subcommands::StateUpdate(cmd) => cmd.run().await,
Subcommands::TransactionReceipt(cmd) => cmd.run().await,
Subcommands::ChainId(cmd) => cmd.run().await,
Subcommands::Balance(cmd) => cmd.run().await,
Subcommands::Nonce(cmd) => cmd.run().await,
Subcommands::Storage(cmd) => cmd.run().await,
Subcommands::ClassHashAt(cmd) => cmd.run().await,
Subcommands::ClassByHash(cmd) => cmd.run().await,
Subcommands::ClassAt(cmd) => cmd.run().await,
Subcommands::Syncing(cmd) => cmd.run().await,
Subcommands::Signer(cmd) => cmd.run(),
Subcommands::Account(cmd) => cmd.run().await,
Subcommands::Invoke(cmd) => cmd.run().await,
Subcommands::Declare(cmd) => cmd.run().await,
Subcommands::Deploy(cmd) => cmd.run().await,
Subcommands::Completions(cmd) => cmd.run(),
Subcommands::Lab(cmd) => cmd.run(),
match (cli.version, cli.command) {
(false, None) => Ok(Cli::command().print_help()?),
(true, _) => {
println!(
"{}",
if cli.verbose {
VERSION_STRING_VERBOSE
} else {
VERSION_STRING
}
);

Ok(())
}
(false, Some(command)) => match command {
Subcommands::Selector(cmd) => cmd.run(),
Subcommands::ClassHash(cmd) => cmd.run(),
Subcommands::ToCairoString(cmd) => cmd.run(),
Subcommands::ParseCairoString(cmd) => cmd.run(),
Subcommands::Mont(cmd) => cmd.run(),
Subcommands::Call(cmd) => cmd.run().await,
Subcommands::Transaction(cmd) => cmd.run().await,
Subcommands::BlockNumber(cmd) => cmd.run().await,
Subcommands::BlockHash(cmd) => cmd.run().await,
Subcommands::Block(cmd) => cmd.run().await,
Subcommands::BlockTime(cmd) => cmd.run().await,
Subcommands::StateUpdate(cmd) => cmd.run().await,
Subcommands::TransactionReceipt(cmd) => cmd.run().await,
Subcommands::ChainId(cmd) => cmd.run().await,
Subcommands::Balance(cmd) => cmd.run().await,
Subcommands::Nonce(cmd) => cmd.run().await,
Subcommands::Storage(cmd) => cmd.run().await,
Subcommands::ClassHashAt(cmd) => cmd.run().await,
Subcommands::ClassByHash(cmd) => cmd.run().await,
Subcommands::ClassAt(cmd) => cmd.run().await,
Subcommands::Syncing(cmd) => cmd.run().await,
Subcommands::Signer(cmd) => cmd.run(),
Subcommands::Account(cmd) => cmd.run().await,
Subcommands::Invoke(cmd) => cmd.run().await,
Subcommands::Declare(cmd) => cmd.run().await,
Subcommands::Deploy(cmd) => cmd.run().await,
Subcommands::Completions(cmd) => cmd.run(),
Subcommands::Lab(cmd) => cmd.run(),
},
}
}

0 comments on commit 00585c1

Please sign in to comment.