mesg-foundation / engine

Build apps or autonomous workflows with reusable, shareable integrations connecting any service, app, blockchain or decentralized network.
https://mesg.com/
Apache License 2.0
130 stars 13 forks source link

Add data to the service execute with no file #256

Closed NicolasMahe closed 6 years ago

NicolasMahe commented 6 years ago

We should have a way to pass a data to the command service execute.

Right now, we have to put the JSON in a file and pass the path with the flag json.

Related to https://github.com/mesg-foundation/core/issues/255

antho1404 commented 6 years ago

Warning: This issue depends on https://github.com/mesg-foundation/core/issues/288, make sure that the https://github.com/mesg-foundation/core/issues/288 issue is fixed before starting this one

antho1404 commented 6 years ago

I updated this issue and talked about data. I really think JSON is not a good way to pass data through the command line we will have to put something like that

mesg-core service execute --task=taskX --data="{\"foo\"=\"bar\"}"

This is terrible and anything other than that will be invalid so json is definitely not good for UX if it's not in a file.

We can find of some ways to do that that would be nicer for the developer.

Maybe something like

mesg-core service execute --task=taskX --foo=bar

But this has a problem if one of the input is the same name than a flag of the command. We could fix this by prefixing with data like:

mesg-core service execute --task=taskX --data-foo=bar

also with that everything will be a string and it will add a lot of complexity on the cli to typecast to the right type which is annoying because the api is already doing this check

I think it's good to be able to add another way than a json file for the data but I would actually go maybe with proposing a yaml file for example and then use env variables if we really want to have this on the console like

DATA_FOO=bar mesg-core service execute --task=taskX --yaml=test.yml

with the following yaml:

foo: ${DATA_FOO}
# even prefixing the type if needed
foo: !!str ${DATA_FOO}
NicolasMahe commented 6 years ago

I'm ok for the yaml file.

For passing data as flag, I don't think it's a good idea. You make a good point.

What about asking questions for every input of the tasks? The CLI could read the service definition and create those questions with the right type.

antho1404 commented 6 years ago

The question is really what we want to provide for the user, if it's a quick and easy way to set the data I really don't think that asking in the console will be quick nor easy.

If this is the real thing that we try to fix maybe we should think about generating these files for the user or something like that.

Otherwise there is another solution similar to curl it will be to add something like that

mesg-core service execute --task taskX --data param1=hello --data param2=bar

this is the way you can give data for the curl command

NicolasMahe commented 6 years ago

I really like it!

Maybe even?

mesg-core service execute --task taskX --data param1=hello param2=bar
antho1404 commented 6 years ago

cannot do something like that because the param2=bar will be interpreted as an argument and not a flag. We could do like url format like --data="param1=foo&param2=bar" still the same "issue" with the types but nothing that the command cannot do.

This is something quite well known by any developers so that might be ok and also I'm not sure the cli lib that we use can handle multiple time the same flag so having all in one would be easier i guess

krhubert commented 6 years ago

https://github.com/mesg-foundation/core/pull/344

I left 3 options - json/json-file/data for further discussion. Also, I left the data map as comma separated as it's more common in shell (& is more common in a web)

NicolasMahe commented 6 years ago

Close by https://github.com/mesg-foundation/core/pull/344