Update dynamic to use client directly and automatically set scope
This commit is contained in:
parent
9caa92a20a
commit
6bc65c10c8
@ -34,8 +34,8 @@ func (c *DynamicCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var r *vagrant_server.Job_RunResult
|
var r *vagrant_server.Job_RunResult
|
||||||
err := c.Do(c.Ctx, func(ctx context.Context, tasker Tasker) (err error) {
|
err := c.Do(c.Ctx, func(ctx context.Context, cl *client.Client, modifier client.JobModifier) (err error) {
|
||||||
tasker.UI().Output("Running "+c.name+"... ", terminal.WithHeaderStyle())
|
cl.UI().Output("Running "+c.name+"... ", terminal.WithHeaderStyle())
|
||||||
taskArgs := &vagrant_plugin_sdk.Command_Arguments{
|
taskArgs := &vagrant_plugin_sdk.Command_Arguments{
|
||||||
Args: args,
|
Args: args,
|
||||||
Flags: []*vagrant_plugin_sdk.Command_Arguments_Flag{},
|
Flags: []*vagrant_plugin_sdk.Command_Arguments_Flag{},
|
||||||
@ -56,26 +56,45 @@ func (c *DynamicCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
taskArgs.Flags = append(taskArgs.Flags, f)
|
taskArgs.Flags = append(taskArgs.Flags, f)
|
||||||
}
|
}
|
||||||
r, err = tasker.Task(ctx, &vagrant_server.Job_RunOp{
|
|
||||||
Task: &vagrant_server.Task{
|
t := &vagrant_server.Task{
|
||||||
Scope: &vagrant_server.Task_Target{
|
Task: c.name,
|
||||||
Target: tasker.(*client.Target).Ref(),
|
Component: &vagrant_server.Component{
|
||||||
},
|
Type: vagrant_server.Component_COMMAND,
|
||||||
Task: c.name,
|
Name: c.name,
|
||||||
Component: &vagrant_server.Component{
|
|
||||||
Type: vagrant_server.Component_COMMAND,
|
|
||||||
Name: c.name,
|
|
||||||
},
|
|
||||||
CliArgs: taskArgs,
|
|
||||||
CommandName: c.name,
|
|
||||||
},
|
},
|
||||||
})
|
CliArgs: taskArgs,
|
||||||
|
CommandName: c.name,
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.basis != nil {
|
||||||
|
t.Scope = &vagrant_server.Task_Basis{
|
||||||
|
Basis: c.basis.Ref(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.project != nil {
|
||||||
|
t.Scope = &vagrant_server.Task_Project{
|
||||||
|
Project: c.project.Ref(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.target != nil {
|
||||||
|
t.Scope = &vagrant_server.Task_Target{
|
||||||
|
Target: c.target.Ref(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err = cl.Task(ctx,
|
||||||
|
&vagrant_server.Job_RunOp{Task: t},
|
||||||
|
modifier,
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tasker.UI().Output("Running of task "+c.name+" failed unexpectedly\n", terminal.WithErrorStyle())
|
cl.UI().Output("Running of task "+c.name+" failed unexpectedly\n", terminal.WithErrorStyle())
|
||||||
tasker.UI().Output("Error: "+err.Error(), terminal.WithErrorStyle())
|
cl.UI().Output("Error: "+err.Error(), terminal.WithErrorStyle())
|
||||||
} else if !r.RunResult {
|
} else if !r.RunResult {
|
||||||
tasker.UI().Output("Error: "+r.RunError.Message+"\n", terminal.WithErrorStyle())
|
cl.UI().Output("Error: "+r.RunError.Message+"\n", terminal.WithErrorStyle())
|
||||||
err = errors.New("execution failed")
|
err = errors.New("execution failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user