unc_cli_rs/js_command_match/
mod.rs

1mod add_key;
2mod call;
3mod clean;
4mod create_account;
5mod delete;
6mod delete_key;
7mod deploy;
8mod dev_deploy;
9mod evm_call;
10mod evm_dev_init;
11mod evm_view;
12mod generate_key;
13mod js;
14mod keys;
15mod login;
16mod proposals;
17mod repl;
18mod send;
19mod set_api_key;
20mod pledge;
21mod state;
22mod tx_status;
23mod validators;
24mod view;
25mod view_state;
26
27#[derive(Debug, Clone, clap::Parser)]
28/// Legacy CLI commands are only supported at best-effort
29pub enum JsCmd {
30    CreateAccount(self::create_account::CreateAccountArgs),
31    State(self::state::StateArgs),
32    Delete(self::delete::DeleteArgs),
33    Keys(self::keys::KeysArgs),
34    TxStatus(self::tx_status::TxStatusArgs),
35    Deploy(self::deploy::DeployArgs),
36    DevDeploy(self::dev_deploy::DevDeployArgs),
37    Call(self::call::CallArgs),
38    View(self::view::ViewArgs),
39    ViewState(self::view_state::ViewStateArgs),
40    Send(self::send::SendArgs),
41    Clean(self::clean::CleanArgs),
42    Pledge(self::pledge::PledgeArgs),
43    Login(self::login::LoginArgs),
44    Repl(self::repl::ReplArgs),
45    GenerateKey(self::generate_key::GenerateKeyArgs),
46    AddKey(self::add_key::AddKeyArgs),
47    DeleteKey(self::delete_key::DeleteKeyArgs),
48    Validators(self::validators::ValidatorsArgs),
49    Proposals(self::proposals::ProposalsArgs),
50    EvmCall(self::evm_call::EvmCallArgs),
51    EvmDevInit(self::evm_dev_init::EvmDevInitArgs),
52    EvmView(self::evm_view::EvmViewArgs),
53    SetApiKey(self::set_api_key::SetApiKeyArgs),
54    Js(self::js::JsArgs),
55}
56
57impl JsCmd {
58    pub fn rust_command_generation(
59        &self,
60    ) -> color_eyre::eyre::Result<(Vec<String>, String), String> {
61        //UNC_ENV=testnet default
62        let network_config = std::env::var("UNC_ENV").unwrap_or_else(|_| "testnet".to_owned());
63        let message = "The command you tried to run is deprecated in the new unc CLI, but we tried our best to match the old command with the new syntax, try it instead:".to_string();
64        let unc_validator_extension_message = "The command you tried to run has been moved into its own CLI extension called unc-validator.\nPlease, follow the installation instructions here: https://github.com/zwong91/utility-validator-cli-rs/blob/main/README.md\nThen run the following command:".to_string();
65        let err_message = "The command you tried to run is deprecated in the new unc CLI and there is no equivalent command in the new unc CLI.".to_string();
66        match self {
67            Self::CreateAccount(create_account_args) => Ok((create_account_args.to_cli_args(network_config), message)),
68            Self::State(state_args) => Ok((state_args.to_cli_args(network_config), message)),
69            Self::Delete(delete_args) => Ok((delete_args.to_cli_args(network_config), message)),
70            Self::Keys(keys_args) => Ok((keys_args.to_cli_args(network_config), message)),
71            Self::TxStatus(tx_status_args) => Ok((tx_status_args.to_cli_args(network_config), message)),
72            Self::Deploy(deploy_args) => Ok((deploy_args.to_cli_args(network_config), message)),
73            Self::DevDeploy(dev_deploy_args) => {
74                dev_deploy_args.to_cli_args(network_config);
75                Err("".to_string())
76            },
77            Self::Call(call_args) => Ok((call_args.to_cli_args(network_config), message)),
78            Self::View(view_args) => Ok((view_args.to_cli_args(network_config), message)),
79            Self::ViewState(view_state_args) => Ok((view_state_args.to_cli_args(network_config), message)),
80            Self::Send(send_args) => Ok((send_args.to_cli_args(network_config), message)),
81            Self::Clean(_) => Err(format!("{err_message}\n\n`clean` command is not implemented, yet. It will be implemented in a dev extension. Meanwhile, keep using the old CLI.")),
82            Self::Pledge(pledge_args) => Ok((pledge_args.to_cli_args(network_config), unc_validator_extension_message)),
83            Self::Login(login_args) => Ok((login_args.to_cli_args(network_config), message)),
84            Self::Repl(_) => Err(format!("{err_message}\n\n`repl` command is not implemented. Use shell scripting for the new CLI.")),
85            Self::GenerateKey(generate_key_args) => {
86                match generate_key_args.to_cli_args(network_config){
87                    Ok(res) => Ok((res, message)),
88                    Err(err) => Err(err.to_string())
89                }
90            },
91            Self::AddKey(add_key_args) => Ok((add_key_args.to_cli_args(network_config), message)),
92            Self::DeleteKey(delete_key_args) => Ok((delete_key_args.to_cli_args(network_config), message)),
93            Self::Validators(validators_args) => Ok((validators_args.to_cli_args(network_config), unc_validator_extension_message)),
94            Self::Proposals(proposals_args) => Ok((proposals_args.to_cli_args(network_config), unc_validator_extension_message)),
95            Self::EvmCall(_) => Err(format!("{err_message}\n\n`evm-call` command is not implemented, yet. It will be implemented in an evm extension. Meanwhile, keep using the old CLI.")),
96            Self::EvmDevInit(_) => Err(format!("{err_message}\n\n`evm-dev-init` command is not implemented, yet. It will be implemented in an evm extension. Meanwhile, keep using the old CLI.")),
97            Self::EvmView(_) => Err(format!("{err_message}\n\n`evm-view` command is not implemented, yet. It will be implemented in an evm extension. Meanwhile, keep using the old CLI.")),
98            Self::SetApiKey(set_api_key_args) => {
99                match set_api_key_args.to_cli_args(network_config){
100                    Ok(res) => Ok((res, message)),
101                    Err(err) => Err(err.to_string())
102                }
103            },
104            Self::Js(_) => Err(format!("{err_message}\n\n`js` command is not implemented. Use shell scripting for the new CLI.")),
105        }
106    }
107}