loambuild / loam

build, deploy, and maintain ambitious smart contracts. monorepo for Loam SDK, CLI, and shared tools.
https://loam.build
2 stars 7 forks source link

Fix/support init scripts with quotes #134

Closed BlaineHeffron closed 1 month ago

BlaineHeffron commented 1 month ago

Fixes https://github.com/loambuild/loam/issues/130

Adds subcommand support and uses shlex to parse the arguments so that it properly respects quoted string arguments.

Limitations

This will not work if you escape quotes inside of quotes. The escaped characters get stripped out by the toml parsing. If you need double quotes in an argument you will need to use single quotes. Or you can escape the escape characters.

To get the init script in the issue to work use this:

[development.contracts.data_feed]
client = true
init = """
admin_set --new-admin me
sep40_init --resolution 300000 --assets '[{"Stellar": "$(stellar contract id asset --asset native)"} ]' --decimals 14 --base '{"Stellar":"$(stellar contract id asset --asset native)"}'
"""

Another limitation is that I run the subcommands through sh if on linux and cmd if on windows. Perhaps we could add an argument to pass the preferred shell. Also, if the subcommand errors, program execution will stop and the error will be printed.

BlaineHeffron commented 1 month ago

One thing I was thinking about is how if the init script fails, it wont be rerun on subsequent build commands since the alias for the contract will be present. This makes me think perhaps we should add a --force-init or something of that nature in case the user wants to force it to be run.

chadoh commented 1 month ago

One thing I was thinking about is how if the init script fails, it wont be rerun on subsequent build commands since the alias for the contract will be present. This makes me think perhaps we should add a --force-init or something of that nature in case the user wants to force it to be run.

yeah, I agree that would be nice. Separate PR for it?

willemneal commented 1 month ago

This looks good enough for me. The ideal way to solve this is (and perhaps I can take a look at it since I did it for smartdeploy) to extract the clap logic from stellar-cli, we could also see about exposing it. This way we don't need to use Command since we can parse the data and do the invoke directly.