@@ -24,14 +24,30 @@ func NewRSyncCommand(binPath string) RSyncCommand {
2424 }
2525}
2626
27+ func NewRSyncSimulateCommand (binPath string ) RSyncCommand {
28+ return RSyncCommand {
29+ BinPath : binPath ,
30+ Simulate : true ,
31+ Executor : & RealSync {},
32+ }
33+ }
34+
35+ func NewListCommand (binPath string ) RSyncCommand {
36+ return RSyncCommand {
37+ BinPath : binPath ,
38+ ListOnly : true ,
39+ Executor : & RealSync {},
40+ }
41+ }
42+
2743func (command RSyncCommand ) GetVersionInfo () (string , error ) {
2844 rsyncPath := command .BinPath
2945
3046 if ! filepath .IsAbs (rsyncPath ) {
3147 return "" , fmt .Errorf ("%w: \" %s\" " , ErrInvalidRsyncPath , rsyncPath )
3248 }
3349
34- output , err := command .Run ("--version" )
50+ output , err := command .Executor . Execute ("--version" )
3551 if err != nil {
3652 return "" , fmt .Errorf ("error fetching rsync version: %w" , err )
3753 }
@@ -44,7 +60,7 @@ func (command RSyncCommand) GetVersionInfo() (string, error) {
4460 return string (output ), nil
4561}
4662
47- func ( command RSyncCommand ) ArgumentsForJob (job Job , logPath string ) []string {
63+ func ArgumentsForJob (job Job , logPath string , simulate bool ) []string {
4864 args := []string {"-aiv" , "--stats" }
4965 if job .Delete {
5066 args = append (args , "--delete" )
@@ -59,13 +75,28 @@ func (command RSyncCommand) ArgumentsForJob(job Job, logPath string) []string {
5975 }
6076
6177 args = append (args , job .Source , job .Target )
62- if command . Simulate {
78+ if simulate {
6379 args = append ([]string {"--dry-run" }, args ... )
6480 }
6581
6682 return args
6783}
6884
69- func (command RSyncCommand ) Run (args ... string ) ([]byte , error ) {
70- return command .Executor .Execute (command .BinPath , args ... )
85+ func (rsync RSyncCommand ) Run (job Job , logPath string ) string {
86+ args := ArgumentsForJob (job , logPath , rsync .Simulate )
87+ fmt .Printf ("Job: %s\n " , job .Name )
88+ fmt .Printf ("Command: rsync %s %s\n " , rsync .BinPath , strings .Join (args , " " ))
89+
90+ if rsync .ListOnly {
91+ return "SUCCESS"
92+ }
93+
94+ out , err := rsync .Executor .Execute (rsync .BinPath , args ... )
95+ fmt .Printf ("Output:\n %s\n " , string (out ))
96+
97+ if err != nil {
98+ return "FAILURE"
99+ }
100+
101+ return "SUCCESS"
71102}
0 commit comments