Skip to content

Commit 563812e

Browse files
committed
feat(pkg/task/lib/cp): Add copy from remote to local
1 parent 2942ce6 commit 563812e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pkg/task/lib/cp/cp.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
package cp
22

33
import (
4+
"fmt"
5+
46
"github.com/sikalabs/gobble/pkg/libtask"
57
"github.com/sikalabs/gobble/pkg/utils/exec_utils"
68
)
79

810
type TaskCp struct {
11+
// Copy from local to remote
912
LocalSrc string `yaml:"local_src"`
1013
RemoteDst string `yaml:"remote_dst"`
14+
// Copy from remote to local
15+
RemoteSrc string `yaml:"remote_src"`
16+
LocalDst string `yaml:"local_dst"`
1117
}
1218

1319
func Run(
1420
taskInput libtask.TaskInput,
1521
taskParams TaskCp,
1622
) libtask.TaskOutput {
17-
err := exec_utils.SCP(taskInput, taskParams.LocalSrc, taskParams.RemoteDst)
18-
return libtask.TaskOutput{
19-
Error: err,
23+
if taskParams.LocalSrc != "" && taskParams.RemoteDst != "" {
24+
err := exec_utils.SCP(taskInput, taskParams.LocalSrc, taskParams.RemoteDst)
25+
return libtask.TaskOutput{
26+
Error: err,
27+
}
28+
} else if taskParams.RemoteSrc != "" && taskParams.LocalDst != "" {
29+
err := exec_utils.SCPRemoteToLocal(taskInput, taskParams.RemoteSrc, taskParams.LocalDst)
30+
return libtask.TaskOutput{
31+
Error: err,
32+
}
33+
} else {
34+
return libtask.TaskOutput{
35+
Error: fmt.Errorf("invalid cp task params"),
36+
}
2037
}
2138
}

pkg/task/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func Run(
3131
switch {
3232
case task.AptInstall.Name != "":
3333
return apt_install.Run(taskInput, task.AptInstall)
34-
case task.Cp.LocalSrc != "":
34+
case task.Cp.LocalSrc != "" || task.Cp.RemoteSrc != "":
3535
return cp.Run(taskInput, task.Cp)
3636
case task.Template.Path != "":
3737
return template.Run(taskInput, task.Template)

0 commit comments

Comments
 (0)