1use crate::{
2 cmd::NodeArgs,
3 substrate_node::{chain_spec, genesis::GenesisConfig},
4};
5use clap::{Parser, Subcommand};
6use foundry_cli::opts::GlobalArgs;
7use foundry_common::version::{LONG_VERSION, SHORT_VERSION};
8use polkadot_sdk::{sc_cli, sc_service};
9
10#[derive(Parser)]
11#[command(name = "anvil-polkadot", version = SHORT_VERSION, long_version = LONG_VERSION, next_display_order = None)]
12pub struct Anvil {
13 #[command(flatten)]
14 pub global: GlobalArgs,
15
16 #[command(flatten)]
17 pub node: NodeArgs,
18
19 #[command(subcommand)]
20 pub cmd: Option<AnvilSubcommand>,
21}
22
23#[derive(Subcommand)]
24pub enum AnvilSubcommand {
25 #[command(visible_alias = "com")]
27 Completions {
28 #[arg(value_enum)]
29 shell: clap_complete::Shell,
30 },
31
32 #[command(visible_alias = "fig")]
34 GenerateFigSpec,
35}
36
37pub struct SubstrateCli {
38 genesis_config: GenesisConfig,
40}
41
42impl SubstrateCli {
43 pub fn new(genesis_config: GenesisConfig) -> Self {
44 Self { genesis_config }
45 }
46}
47
48impl sc_cli::SubstrateCli for SubstrateCli {
50 fn impl_name() -> String {
51 "Anvil Substrate Node".into()
52 }
53
54 fn impl_version() -> String {
55 SHORT_VERSION.into()
56 }
57
58 fn description() -> String {
59 "Anvil Substrate Node".into()
60 }
61
62 fn author() -> String {
63 "Anvil Polkadot Developers".into()
64 }
65
66 fn support_url() -> String {
67 "https://github.com/paritytech/foundry-polkadot/issues".into()
68 }
69
70 fn copyright_start_year() -> i32 {
71 2025
72 }
73
74 fn executable_name() -> String {
75 "anvil-polkadot".into()
76 }
77
78 fn load_spec(&self, _: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
79 Ok(Box::new(chain_spec::development_chain_spec(self.genesis_config.clone())?))
80 }
81}