Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data to the service execute with no file #344

Merged
merged 7 commits into from
Aug 9, 2018
Merged

Add data to the service execute with no file #344

merged 7 commits into from
Aug 9, 2018

Conversation

krhubert
Copy link
Contributor

@krhubert krhubert commented Aug 6, 2018

related to #256

Copy link
Member

@NicolasMahe NicolasMahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is xpflag? Can you provide some example on how to use it?

if (data != "" && jsonStr != "") ||
(data != "" && jsonFile != "") ||
(jsonStr != "" && jsonFile != "") {
return "", errors.New("data, json and json-file flags are mutually exclusive")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write something more user friendly like: "You can use only of one of the following flags: 'data', 'json' and 'json-file'."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

As xpflag is eXtension to spf13/pflag that contains custom flags (implements pflag.Value interface) and I put it in different package.

@antho1404
Copy link
Member

This one will definitely need some update on the documentation and changelog and also I'm not really sure about it first we already have a json that reads a file and not it does something different. Also I don't see the point of having a json directly in the command (not in the file) and having a data.

@krhubert
Copy link
Contributor Author

krhubert commented Aug 6, 2018

@antho1404 For sure, I've kept 3 options for further discussion (which of them should/shouldn't stay).
As for JSON in command, I find it frustrating when I wanted to execute some task I had to create a file with simple JSON, then edit the file in order to execute with different task data, etc...

It's nice to have json in cmd:

$ mesg-core service test --task execute --data '{"key":"1"}'
$ mesg-core service test --task execute --data '{"key":"2"}'
$ # do more 

@antho1404
Copy link
Member

I was actually against json as parameter because if using double quotes it looks like
"{\"foo\":\"bar\"}" which is terrible to write but with single quotes it's way better. I'm just afraid for a user perspective they might do this mistake and spend hours to understand why their data are not good. Users might be junior developers so probably not that much comfortable with the terminal.

I like the data part but this will be interpreted as string and if the data needs to be boolean for example the core will reject the task so this is something to manage too

Copy link
Member

@NicolasMahe NicolasMahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON with space doesn't work when passed:

service execute v1_120cc5caa2a7ccea96767d19929ad6fb --task transfer --json  '{"to": "0xadwwadawd", "value": 27, "contractAddress": "0xdawdwaw", "privateKey": "0xawdawawd"}'

I'm not sure what to do with JSON. It's quite terrible to use JSON in the terminal....
I'm happy remove the --json and keep the --data flag.


And as said by Anthony, data flag return only strings type:

./dev-cli service execute v1_120cc5caa2a7ccea96767d19929ad6fb --task transfer --data to=0xwadadawd,value=27,contractAddress=0xdwdwdwdw,privateKey=0xdwdwdwdw

⣻ Executing task transfer... rpc error: code = Unknown desc = Inputs of task 'transfer' are invalid. Value of 'value' is not a number

@krhubert Can you cast the type when using the flag data? You can use the API GetService to access the service's definition.

serviceReply, err := cli().GetService(context.Background(), &core.GetServiceRequest{
  ServiceID: serviceID,
})

@@ -11,11 +13,13 @@ import (
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/utils/xpflag"
"github.com/spf13/cobra"
survey "gopkg.in/AlecAivazis/survey.v1"
)

var executions []*core.ResultData
Copy link
Member

@NicolasMahe NicolasMahe Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executions is not used. (not related to this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't get it, what do you mean? executions wasn't touched

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know, that's why I said "(not related to this PR)". But still, could you remove it?

@NicolasMahe
Copy link
Member

@mesg-foundation/core What about asking the value of the task's inputs by questions if no data has been passed by flags? It's not the most efficient way to pass data, but for a quick test of a task it's super convenient! No need to know the inputs before executing the command.

@krhubert
Copy link
Contributor Author

krhubert commented Aug 7, 2018

I don't like asking about the data. It makes harder for debuging (if someone run the cli in some script and it hangs waiting for user input). I prefer return non 0 value + message

@NicolasMahe
Copy link
Member

NicolasMahe commented Aug 7, 2018

We ask quite a lot of questions in the different command already.
We only ask when flags don't exist. So from a script, the dev will use flags.

@NicolasMahe
Copy link
Member

NicolasMahe commented Aug 7, 2018

To sum up the conversion on discord:

@antho1404
Copy link
Member

antho1404 commented Aug 7, 2018

I would add also

@krhubert krhubert force-pushed the issues/256 branch 2 times, most recently from c752a0e to c1fdd26 Compare August 7, 2018 19:36
service/cast.go Outdated
func (s *Service) Cast(taskKey string, taskData map[string]string) (map[string]interface{}, error) {
task, ok := s.Tasks[taskKey]
if !ok {
return nil, fmt.Errorf("Task %q not found", taskKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

service/cast.go Outdated
for key, value := range taskData {
inputType, ok := task.Inputs[key]
if !ok {
return nil, fmt.Errorf("Task %q has no input named %q", taskKey, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a new type for this error in service/error.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

service/cast.go Outdated
}
m[key] = b
case "Object":
return nil, fmt.Errorf("Task %q - input %q - Object type is not supported", taskKey, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we really not pass any Object with the CLI? Even a JSON stringified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At what level do you want to block it?

Someone can pass --data myObject=.... and we need to check the type and cast it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be ok not to support this yet, we also have an issue to remove this and add more details on this object so it's ok if for now we don't support it.

But anyway there is no validation on the API so we could send anything so maybe we can just bypass this instead of returning an error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I'll continue here instead of return an error

@krhubert krhubert force-pushed the issues/256 branch 2 times, most recently from 9ae5b4e to 01210f5 Compare August 8, 2018 09:56
NicolasMahe
NicolasMahe previously approved these changes Aug 8, 2018
service/cast.go Outdated
}
func castObject(value string) (interface{}, error) {
// do not cast object type
return nil, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not returning any value so any service with object will fail.

We can add a basic support by at least returning the value or even better trying to parse it from string

Copy link
Member

@antho1404 antho1404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good for me, nice job 👍

Copy link
Member

@NicolasMahe NicolasMahe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 👍

@NicolasMahe NicolasMahe merged commit 2c7175d into dev Aug 9, 2018
@NicolasMahe NicolasMahe deleted the issues/256 branch August 9, 2018 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants