feat(flags): add '-seq' flag for running a command sequentially.

Change-Id: I279208548c0ab61edd3a976ff5bb0ebff3837394
Closes #9
diff --git a/doc.go b/doc.go
index 3250314..972fc06 100644
--- a/doc.go
+++ b/doc.go
@@ -39,6 +39,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 The global flags are:
  -metadata=<just specify -metadata to activate>
@@ -94,6 +96,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb exec - Run the provided adb command on all devices and emulators concurrently
 
@@ -139,6 +143,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb install - Install your app on all devices
 
@@ -198,6 +204,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb name - Manage device nicknames
 
@@ -294,6 +302,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb start - Launch your app on all devices
 
@@ -375,6 +385,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb stop - Stop your app on all devices
 
@@ -427,6 +439,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb uninstall - Uninstall your app from all devices
 
@@ -478,6 +492,8 @@
    '@2'), or nicknames (set by 'madb name'). A device index is specified by an
    '@' sign followed by the index of the device in the output of 'adb devices'
    command, starting from 1. Command will be run only on specified devices.
+ -seq=false
+   Run the command sequentially, instead of running it in parallel.
 
 Madb user - Manage default user settings for each device
 
diff --git a/madb.go b/madb.go
index e3b26a9..9b2fe79 100644
--- a/madb.go
+++ b/madb.go
@@ -36,6 +36,7 @@
 	allDevicesFlag   bool
 	allEmulatorsFlag bool
 	devicesFlag      string
+	sequentialFlag   bool
 
 	clearCacheFlag bool
 	moduleFlag     string
@@ -50,6 +51,7 @@
 	cmdMadb.Flags.BoolVar(&allDevicesFlag, "d", false, `Restrict the command to only run on real devices.`)
 	cmdMadb.Flags.BoolVar(&allEmulatorsFlag, "e", false, `Restrict the command to only run on emulators.`)
 	cmdMadb.Flags.StringVar(&devicesFlag, "n", "", `Comma-separated device serials, qualifiers, device indices (e.g., '@1', '@2'), or nicknames (set by 'madb name'). A device index is specified by an '@' sign followed by the index of the device in the output of 'adb devices' command, starting from 1. Command will be run only on specified devices.`)
+	cmdMadb.Flags.BoolVar(&sequentialFlag, "seq", false, `Run the command sequentially, instead of running it in parallel.`)
 
 	// Store the current working directory.
 	var err error
@@ -388,26 +390,33 @@
 		args = newArgs
 	}
 
-	wg := sync.WaitGroup{}
-
 	var errs []error
 	var errDevices []device
 
-	for _, d := range devices {
-		// Capture the current value.
-		deviceCopy := d
-
-		wg.Add(1)
-		go func() {
-			if err := r.subCmd(env, args, deviceCopy, properties); err != nil {
+	if sequentialFlag {
+		for _, d := range devices {
+			if err := r.subCmd(env, args, d, properties); err != nil {
 				errs = append(errs, err)
-				errDevices = append(errDevices, deviceCopy)
+				errDevices = append(errDevices, d)
 			}
-			wg.Done()
-		}()
-	}
+		}
+	} else {
+		wg := sync.WaitGroup{}
+		for _, d := range devices {
+			// Capture the current device value, and run the command in a go-routine.
+			deviceCopy := d
 
-	wg.Wait()
+			wg.Add(1)
+			go func() {
+				if err := r.subCmd(env, args, deviceCopy, properties); err != nil {
+					errs = append(errs, err)
+					errDevices = append(errDevices, deviceCopy)
+				}
+				wg.Done()
+			}()
+		}
+		wg.Wait()
+	}
 
 	// Report any errors returned from the go-routines.
 	if errs != nil {