Refactor CLI handling (#1368)

* Rework cli handling

* Update readme

* Adds support for custom subcommands and extra run parameters

* Update readme

* Fixes compilation after master merge

* Make "Run" the default subcommand

Actually its hidden to the outside that is an subcommand.

* Rewrite CLI to work without breaking old CLI behavior

* Some cleanup

* Fix incorrect config setup

* Update README

* Fixes after merge

* Fixes incorrect README
This commit is contained in:
Bastian Köcher
2019-01-25 11:48:46 +01:00
committed by Gav Wood
parent 375e01e6b1
commit 27a882bfac
13 changed files with 814 additions and 575 deletions
+11 -4
View File
@@ -25,16 +25,23 @@ use std::{fs, path::Path};
const SECRET_FILE: &str = "secret";
/// Obtains or generates the local private key using the configuration.
pub fn obtain_private_key(
pub fn obtain_private_key_from_config(
config: &NetworkConfiguration
) -> Result<secio::SecioKeyPair, IoError> {
if let Some(ref secret) = config.use_secret {
obtain_private_key(&config.use_secret, &config.net_config_path)
}
/// Obtains or generates the local private key using the configuration.
pub fn obtain_private_key(
secret: &Option<[u8; 32]>,
net_config_path: &Option<String>,
) -> Result<secio::SecioKeyPair, IoError> {
if let Some(ref secret) = secret {
// Key was specified in the configuration.
secio::SecioKeyPair::secp256k1_raw_key(&secret[..])
.map_err(|err| IoError::new(IoErrorKind::InvalidData, err))
} else {
if let Some(ref path) = config.net_config_path {
if let Some(ref path) = net_config_path {
// Try fetch the key from a the file containing the secret.
let secret_path = Path::new(path).join(SECRET_FILE);
match load_private_key_from_file(&secret_path) {
@@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use crate::{behaviour::Behaviour, behaviour::BehaviourOut, secret::obtain_private_key, transport};
use crate::{
behaviour::Behaviour, behaviour::BehaviourOut, secret::obtain_private_key_from_config,
transport
};
use crate::custom_proto::{RegisteredProtocol, RegisteredProtocols};
use crate::topology::NetTopology;
use crate::{Error, NetworkConfiguration, NodeIndex, ProtocolId, parse_str_addr};
@@ -51,7 +54,7 @@ where TProtos: IntoIterator<Item = RegisteredProtocol> {
}
// Private and public keys configuration.
let local_private_key = obtain_private_key(&config)?;
let local_private_key = obtain_private_key_from_config(&config)?;
let local_public_key = local_private_key.to_public_key();
let local_peer_id = local_public_key.clone().into_peer_id();