1
1
// Copyright (C) Parity Technologies (UK) Ltd.
2
2
// This file is part of Cumulus.
3
3
// SPDX-License-Identifier: Apache-2.0
4
-
4
+ //
5
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
6
// you may not use this file except in compliance with the License.
7
7
// You may obtain a copy of the License at
8
8
//
9
- // http://www.apache.org/licenses/LICENSE-2.0
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
10
//
11
11
// Unless required by applicable law or agreed to in writing, software
12
12
// distributed under the License is distributed on an "AS IS" BASIS,
21
21
22
22
mod chain_spec;
23
23
24
- use polkadot_omni_node_lib:: { run, CliConfig as CliConfigT , RunConfig , NODE_VERSION } ;
24
+ use clap:: { Command , CommandFactory , FromArgMatches } ;
25
+ use color_eyre:: eyre;
26
+ use polkadot_omni_node_lib:: {
27
+ chain_spec:: LoadSpec , cli:: Cli as OmniCli , run, CliConfig as CliConfigT , RunConfig ,
28
+ NODE_VERSION ,
29
+ } ;
30
+ use sc_cli:: ExportChainSpecCmd ;
25
31
32
+ /// Custom CLI configuration for metadata.
26
33
struct CliConfig ;
27
34
28
35
impl CliConfigT for CliConfig {
@@ -44,12 +51,31 @@ impl CliConfigT for CliConfig {
44
51
}
45
52
}
46
53
47
- fn main ( ) -> color_eyre :: eyre:: Result < ( ) > {
54
+ fn main ( ) -> eyre:: Result < ( ) > {
48
55
color_eyre:: install ( ) ?;
49
56
50
- let config = RunConfig :: new (
51
- Box :: new ( chain_spec:: RuntimeResolver ) ,
52
- Box :: new ( chain_spec:: ChainSpecLoader ) ,
53
- ) ;
54
- Ok ( run :: < CliConfig > ( config) ?)
57
+ // Build the omni-node CLI command with version info.
58
+ let mut cmd: Command = OmniCli :: < CliConfig > :: command ( ) . version ( NODE_VERSION ) ;
59
+
60
+ // Add our export command under the new name "export-chain-spec".
61
+ cmd = cmd. subcommand ( ExportChainSpecCmd :: command ( ) . name ( "export-chain-spec" ) ) ;
62
+
63
+ // Parse the combined CLI.
64
+ let matches = cmd. get_matches ( ) ;
65
+
66
+ // If the export-chain-spec subcommand is invoked, execute that branch.
67
+ if let Some ( export_matches) = matches. subcommand_matches ( "export-chain-spec" ) {
68
+ // Clone the matches to get an owned mutable instance.
69
+ let mut export_matches_owned = export_matches. clone ( ) ;
70
+ let export_cmd = ExportChainSpecCmd :: from_arg_matches_mut ( & mut export_matches_owned) ?;
71
+ let loader = chain_spec:: ChainSpecLoader ;
72
+ let spec = loader. load_spec ( & export_cmd. chain ) . map_err ( |e : String | eyre:: eyre!( e) ) ?;
73
+ export_cmd. run ( spec) . map_err ( Into :: into)
74
+ } else {
75
+ let config = RunConfig :: new (
76
+ Box :: new ( chain_spec:: RuntimeResolver ) ,
77
+ Box :: new ( chain_spec:: ChainSpecLoader ) ,
78
+ ) ;
79
+ Ok ( run :: < CliConfig > ( config) ?)
80
+ }
55
81
}
0 commit comments