1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
mod asset;
mod cosmwasm;
mod cw_ownable;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

use crate::{types::CliLockedChain, GlobalConfig};

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = GlobalConfig)]
#[interactive_clap(output_context = CosmosContext)]
pub struct CosmosCommands {
    #[interactive_clap(skip_default_input_arg)]
    /// Chain id
    chain_id: CliLockedChain,
    #[interactive_clap(subcommand)]
    action: CosmosAction,
}

#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
#[interactive_clap(context = CosmosContext)]
/// Select type of cosmos action
pub enum CosmosAction {
    /// Cosmwasm Action: store, instantiate, execute or query cosmwasm contract
    #[strum_discriminants(strum(message = "🔮 CosmWasm"))]
    Cw(cosmwasm::CwCommands),
    /// Asset Action
    #[strum_discriminants(strum(message = "🏦 Asset"))]
    Asset(asset::AssetCommands),
    /// CW-Ownable Action
    #[strum_discriminants(strum(message = "👑 CW-Ownable"))]
    CwOwnable(cw_ownable::CwOwnableCommands),
}

impl CosmosCommands {
    fn input_chain_id(_context: &GlobalConfig) -> color_eyre::eyre::Result<Option<CliLockedChain>> {
        crate::common::select_chain()
    }
}

impl From<CosmosContext> for () {
    fn from(_value: CosmosContext) -> Self {}
}

#[derive(Clone)]
pub struct CosmosContext {
    pub chain: CliLockedChain,
    pub global_config: GlobalConfig,
}

impl CosmosContext {
    fn from_previous_context(
        previous_context: GlobalConfig,
        scope:&<CosmosCommands as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
    ) -> color_eyre::eyre::Result<Self> {
        Ok(CosmosContext {
            chain: scope.chain_id,
            global_config: previous_context,
        })
    }
}