Browse code

oc rsync: allow multiple include or exclude patterns

Cesar Wong authored on 2016/08/02 04:49:11
Showing 5 changed files
... ...
@@ -38,11 +38,11 @@ for the copy.
38 38
     Delete files not present in source
39 39
 
40 40
 .PP
41
-\fB\-\-exclude\fP=""
41
+\fB\-\-exclude\fP=[]
42 42
     rsync \- exclude files matching specified pattern
43 43
 
44 44
 .PP
45
-\fB\-\-include\fP=""
45
+\fB\-\-include\fP=[]
46 46
     rsync \- include files matching specified pattern
47 47
 
48 48
 .PP
... ...
@@ -38,11 +38,11 @@ for the copy.
38 38
     Delete files not present in source
39 39
 
40 40
 .PP
41
-\fB\-\-exclude\fP=""
41
+\fB\-\-exclude\fP=[]
42 42
     rsync \- exclude files matching specified pattern
43 43
 
44 44
 .PP
45
-\fB\-\-include\fP=""
45
+\fB\-\-include\fP=[]
46 46
     rsync \- include files matching specified pattern
47 47
 
48 48
 .PP
... ...
@@ -77,8 +77,8 @@ type RsyncOptions struct {
77 77
 	Delete        bool
78 78
 	Watch         bool
79 79
 
80
-	RsyncInclude  string
81
-	RsyncExclude  string
80
+	RsyncInclude  []string
81
+	RsyncExclude  []string
82 82
 	RsyncProgress bool
83 83
 	RsyncNoPerms  bool
84 84
 
... ...
@@ -113,8 +113,8 @@ func NewCmdRsync(name, parent string, f *clientcmd.Factory, out, errOut io.Write
113 113
 	// Flags for rsync options, Must match rsync flag names
114 114
 	cmd.Flags().BoolVarP(&o.Quiet, "quiet", "q", false, "Suppress non-error messages")
115 115
 	cmd.Flags().BoolVar(&o.Delete, "delete", false, "Delete files not present in source")
116
-	cmd.Flags().StringVar(&o.RsyncExclude, "exclude", "", "rsync - exclude files matching specified pattern")
117
-	cmd.Flags().StringVar(&o.RsyncInclude, "include", "", "rsync - include files matching specified pattern")
116
+	cmd.Flags().StringSliceVar(&o.RsyncExclude, "exclude", nil, "rsync - exclude files matching specified pattern")
117
+	cmd.Flags().StringSliceVar(&o.RsyncInclude, "include", nil, "rsync - include files matching specified pattern")
118 118
 	cmd.Flags().BoolVar(&o.RsyncProgress, "progress", false, "rsync - show progress during transfer")
119 119
 	cmd.Flags().BoolVar(&o.RsyncNoPerms, "no-perms", false, "rsync - do not transfer permissions")
120 120
 	cmd.Flags().BoolVarP(&o.Watch, "watch", "w", false, "Watch directory for changes and resync automatically")
... ...
@@ -89,10 +89,14 @@ func rsyncFlagsFromOptions(o *RsyncOptions) []string {
89 89
 		flags = append(flags, "--delete")
90 90
 	}
91 91
 	if len(o.RsyncInclude) > 0 {
92
-		flags = append(flags, fmt.Sprintf("--include=%s", o.RsyncInclude))
92
+		for _, include := range o.RsyncInclude {
93
+			flags = append(flags, fmt.Sprintf("--include=%s", include))
94
+		}
93 95
 	}
94 96
 	if len(o.RsyncExclude) > 0 {
95
-		flags = append(flags, fmt.Sprintf("--exclude=%s", o.RsyncExclude))
97
+		for _, exclude := range o.RsyncExclude {
98
+			flags = append(flags, fmt.Sprintf("--exclude=%s", exclude))
99
+		}
96 100
 	}
97 101
 	if o.RsyncProgress {
98 102
 		flags = append(flags, "--progress")
... ...
@@ -301,6 +301,23 @@ var _ = g.Describe("[cli][Slow] can use rsync to upload files to pods", func() {
301 301
 			o.Expect(result).NotTo(o.ContainSubstring("image-streams-rhel7.json"))
302 302
 		})
303 303
 
304
+		g.It("should honor multiple --exclude flags", func() {
305
+			g.By(fmt.Sprintf("Calling oc rsync %s %s:/tmp --exclude=application-template-custombuild.json --exclude=application-template-dockerbuild.json", sourcePath2, podName))
306
+			err := oc.Run("rsync").Args(
307
+				sourcePath2,
308
+				fmt.Sprintf("%s:/tmp", podName),
309
+				"--exclude=application-template-custombuild.json",
310
+				"--exclude=application-template-dockerbuild.json").Execute()
311
+			o.Expect(err).NotTo(o.HaveOccurred())
312
+
313
+			g.By("Verifying that files are copied to the container")
314
+			result, err := oc.Run("rsh").Args(podName, "ls", "/tmp/sample-app").Output()
315
+			o.Expect(err).NotTo(o.HaveOccurred())
316
+			o.Expect(result).NotTo(o.ContainSubstring("application-template-custombuild.json"))
317
+			o.Expect(result).NotTo(o.ContainSubstring("application-template-dockerbuild.json"))
318
+			o.Expect(result).To(o.ContainSubstring("application-template-stibuild.json"))
319
+		})
320
+
304 321
 		g.It("should honor the --include flag", func() {
305 322
 			g.By(fmt.Sprintf("Calling oc rsync %s %s:/tmp --exclude=*.json --include=image-streams-rhel7.json", sourcePath1, podName))
306 323
 			err := oc.Run("rsync").Args(
... ...
@@ -317,6 +334,24 @@ var _ = g.Describe("[cli][Slow] can use rsync to upload files to pods", func() {
317 317
 			o.Expect(result).NotTo(o.ContainSubstring("image-streams-centos7.json"))
318 318
 		})
319 319
 
320
+		g.It("should honor multiple --include flags", func() {
321
+			g.By(fmt.Sprintf("Calling oc rsync %s %s:/tmp --exclude=*.json --include=application-template-custombuild.json --include=application-template-dockerbuild.json", sourcePath2, podName))
322
+			err := oc.Run("rsync").Args(
323
+				sourcePath2,
324
+				fmt.Sprintf("%s:/tmp", podName),
325
+				"--exclude=*.json",
326
+				"--include=application-template-custombuild.json",
327
+				"--include=application-template-dockerbuild.json").Execute()
328
+			o.Expect(err).NotTo(o.HaveOccurred())
329
+
330
+			g.By("Verifying that files are copied to the container")
331
+			result, err := oc.Run("rsh").Args(podName, "ls", "/tmp/sample-app").Output()
332
+			o.Expect(err).NotTo(o.HaveOccurred())
333
+			o.Expect(result).To(o.ContainSubstring("application-template-custombuild.json"))
334
+			o.Expect(result).To(o.ContainSubstring("application-template-dockerbuild.json"))
335
+			o.Expect(result).NotTo(o.ContainSubstring("application-template-stibuild.json"))
336
+		})
337
+
320 338
 		g.It("should honor the --progress flag", func() {
321 339
 			g.By(fmt.Sprintf("Calling oc rsync %s %s:/tmp --progress", sourcePath1, podName))
322 340
 			result, err := oc.Run("rsync").Args(