-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
There was a problem hiding this 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?
cmd/service/execute.go
Outdated
if (data != "" && jsonStr != "") || | ||
(data != "" && jsonFile != "") || | ||
(jsonStr != "" && jsonFile != "") { | ||
return "", errors.New("data, json and json-file flags are mutually exclusive") |
There was a problem hiding this comment.
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'."
There was a problem hiding this comment.
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.
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 |
@antho1404 For sure, I've kept 3 options for further discussion (which of them should/shouldn't stay). It's nice to have json in cmd:
|
I was actually against json as parameter because if using double quotes it looks like 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 |
There was a problem hiding this 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,
})
cmd/service/execute.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
@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. |
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 |
We ask quite a lot of questions in the different command already. |
To sum up the conversion on discord:
|
I would add also
|
c752a0e
to
c1fdd26
Compare
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use TaskNotFoundError
type.
See: https://github.com/mesg-foundation/core/blob/dev/service/error.go#L28-L36
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
9ae5b4e
to
01210f5
Compare
service/cast.go
Outdated
} | ||
func castObject(value string) (interface{}, error) { | ||
// do not cast object type | ||
return nil, nil |
There was a problem hiding this comment.
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
There was a problem hiding this 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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👍
related to #256