Skip to content
Snippets Groups Projects
cli.rs 2.75 KiB
Newer Older
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.

use sc_cli::RunCmd;
use std::str::FromStr;
Pascal Engélibert's avatar
Pascal Engélibert committed
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct Cli {
Pascal Engélibert's avatar
Pascal Engélibert committed
    #[structopt(subcommand)]
    pub subcommand: Option<Subcommand>,
Pascal Engélibert's avatar
Pascal Engélibert committed
    #[structopt(flatten)]
    pub run: RunCmd,

    /// When blocks should be sealed in the dev service.
    ///
    /// Options are "instant", "manual", or timer interval in milliseconds
    #[structopt(long, default_value = "6000")]
    pub sealing: Sealing,

#[derive(Debug, StructOpt)]
pub enum Subcommand {
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Key management cli utilities
    Key(sc_cli::KeySubcommand),
    /// Build a chain specification.
    BuildSpec(sc_cli::BuildSpecCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Validate blocks.
    CheckBlock(sc_cli::CheckBlockCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Export blocks.
    ExportBlocks(sc_cli::ExportBlocksCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Export the state of a given block into a chain spec.
    ExportState(sc_cli::ExportStateCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Import blocks.
    ImportBlocks(sc_cli::ImportBlocksCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Remove the whole chain.
    PurgeChain(sc_cli::PurgeChainCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// Revert the chain to a previous state.
    Revert(sc_cli::RevertCmd),
Pascal Engélibert's avatar
Pascal Engélibert committed
    /// The custom benchmark subcommmand benchmarking runtime pallets.
    #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
    Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Block authoring scheme to be used by the dev service.
#[derive(Debug)]
pub enum Sealing {
    /// Author a block immediately upon receiving a transaction into the transaction pool
    Instant,
    /// Author a block upon receiving an RPC command
    Manual,
    /// Author blocks at a regular interval specified in milliseconds
    Interval(u64),
}

impl FromStr for Sealing {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match s {
            "instant" => Self::Instant,
            "manual" => Self::Manual,
            s => {
                let millis = s
                    .parse::<u64>()
                    .map_err(|_| "couldn't decode sealing param")?;
                Self::Interval(millis)
            }
        })
    }
}