r0gue-io / pop-cli

An all-in-one tool for Polkadot development.
GNU General Public License v3.0
74 stars 21 forks source link

chore: accept strings as arguments from command line without having to use `Some()` #319

Closed brunopgalvao closed 1 week ago

brunopgalvao commented 1 month ago

When instantiating a contract that expects String's as arguments, Pop CLI fails:

For example, instantiating the PSP22 contract:

#[ink(constructor)]
pub fn new(
    supply: u128,
    name: Option<String>,
    symbol: Option<String>,
    decimals: u8,
) -> Self {
    let (data, events) = PSP22Data::new(supply, Self::env().caller()); // (2)
    let contract = Self {
        data,
        name,
        symbol,
        decimals,
    };
    contract.emit_events(events);
    contract
}
pop up contract --constructor new --args 10000000, "AWESOME", "AWE", 10

The following error is emitted:

┌   Pop CLI : Deploy a smart contract
│
■  An error occurred instantiating the contract: No variant 'AWESOME' found

For it to work, I need to wrap the strings in Some() with '' around so that zsh does not complain:

pop up contract --constructor new --args 10000000, 'Some("AWESOME")', 'Some("AWE")', 10
brunopgalvao commented 3 weeks ago

So yes, the user should just pass in arguments without Rust syntax, so if the argument is None then have it be empty e.g.

This:

pop up contract --constructor new --args 10000000, 'None', 'Some("AWE")', 10

Would be:

pop up contract --constructor new --args 10000000, , "AWE", 10

All the following variations should be okay:

pop up contract --constructor new --args 10000000, "", "AWE", 10

OR

pop up contract --constructor new --args supply=10000000, name=, symbol="AWE", decimals=10

OR

pop up contract --constructor new --args supply=10000000, name="", symbol=AWE, decimals="10"

Pop CLI should (attempt) to parse into the appropriate type.

brunopgalvao commented 1 week ago

https://github.com/r0gue-io/pop-cli/pull/330 solves this issue