-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor args #805
Refactor args #805
Changes from all commits
606bc3b
486e85d
f117fab
40ddf19
e7d16c3
2906370
7a0963e
bde61a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SUBXT_URL=wss://westend-rpc.polkadot.io:443 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/target | ||
**/*.rs.bk | ||
**/.DS_Store | ||
cargo-timing* | ||
cargo-timing* | ||
.env* | ||
!.env-example |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
pub mod codegen; | ||
pub mod compatibility; | ||
pub mod metadata; | ||
mod source; | ||
pub mod version; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::path::{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the convention that all files in |
||
Path, | ||
PathBuf, | ||
}; | ||
use subxt_codegen::utils::Uri; | ||
|
||
/// The Source can be either a valid existing `File` or a `Url` | ||
#[derive(Debug, PartialEq, Clone)] | ||
pub enum Source { | ||
File(PathBuf), | ||
Url(Uri), | ||
} | ||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool; like this! |
||
|
||
impl TryFrom<&str> for Source { | ||
type Error = String; | ||
fn try_from(s: &str) -> Result<Self, Self::Error> { | ||
match s { | ||
s if (s.starts_with("ws://") | ||
| s.starts_with("wss://") | ||
| s.starts_with("http://") | ||
| s.starts_with("https://")) | ||
&& s.parse::<Uri>().is_ok() => | ||
{ | ||
Ok(Source::Url(s.parse().unwrap())) | ||
} | ||
p if Path::new(p).exists() => Ok(Source::File(PathBuf::from(p))), | ||
_ => Err(format!("File does not exist: {s}")), | ||
} | ||
Comment on lines
+17
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to just stick with |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use clap::Parser as ClapParser; | ||
|
||
use crate::CliOpts; | ||
|
||
/// Prints version information | ||
#[derive(Debug, ClapParser)] | ||
pub struct Opts {} | ||
pub struct Version {} | ||
|
||
pub fn run(_opts: Opts) -> color_eyre::Result<()> { | ||
pub fn run(_opts: &CliOpts, _cmd_opts: &Version) -> color_eyre::Result<()> { | ||
let git_hash = env!("GIT_HASH"); | ||
println!( | ||
"{} {}-{}", | ||
clap::crate_name!(), | ||
clap::crate_version!(), | ||
git_hash | ||
); | ||
let name = clap::crate_name!(); | ||
let version = clap::crate_version!(); | ||
println!("{name} {version}-{git_hash}"); | ||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,41 @@ | |
#![deny(unused_crate_dependencies)] | ||
|
||
mod commands; | ||
use clap::Parser as ClapParser; | ||
use clap::{ | ||
crate_authors, | ||
crate_version, | ||
ColorChoice, | ||
Parser as ClapParser, | ||
Parser, | ||
}; | ||
|
||
/// Subxt utilities for interacting with Substrate based nodes. | ||
#[derive(Debug, ClapParser)] | ||
enum Command { | ||
Metadata(commands::metadata::Opts), | ||
Codegen(commands::codegen::Opts), | ||
Compatibility(commands::compatibility::Opts), | ||
Version(commands::version::Opts), | ||
pub enum SubCommand { | ||
Metadata(commands::metadata::MetadataOpts), | ||
Codegen(commands::codegen::CodegenOpts), | ||
Compatibility(commands::compatibility::CompatOpts), | ||
Version(commands::version::Version), | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(version = crate_version!(), author = crate_authors!(), color=ColorChoice::Always)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pub struct CliOpts { | ||
#[clap(subcommand)] | ||
pub subcmd: SubCommand, | ||
Comment on lines
+18
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any advantage to these being two structs and not one struct like before now? |
||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> color_eyre::Result<()> { | ||
color_eyre::install()?; | ||
let args = Command::parse(); | ||
let opts = CliOpts::parse(); | ||
|
||
match args { | ||
Command::Metadata(opts) => commands::metadata::run(opts).await, | ||
Command::Codegen(opts) => commands::codegen::run(opts).await, | ||
Command::Compatibility(opts) => commands::compatibility::run(opts).await, | ||
Command::Version(opts) => commands::version::run(opts), | ||
match &opts.subcmd { | ||
SubCommand::Metadata(cmd_opts) => commands::metadata::run(&opts, cmd_opts).await, | ||
SubCommand::Codegen(cmd_opts) => commands::codegen::run(&opts, cmd_opts).await, | ||
SubCommand::Compatibility(cmd_opts) => { | ||
commands::compatibility::run(&opts, cmd_opts).await | ||
} | ||
SubCommand::Version(cmd_opts) => commands::version::run(&opts, cmd_opts), | ||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we stop passing |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the original doc format (in other words; show the simplest steps here and mention below using
--url
or the newSUBXT_URL
env var to set the URL).