run pub for analyze and test (#3310)

* run pub for analyze and test

* don't run pub when doing repo analysis

* move logic for when to run pub into the commands

* re-write ternary expression
diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart
index 73bc0c4..a2b3f48 100644
--- a/packages/flutter_tools/lib/src/runner/flutter_command.dart
+++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart
@@ -41,6 +41,8 @@
 
   bool _usesPubOption = false;
 
+  bool get shouldRunPub => _usesPubOption && argResults['pub'];
+
   List<BuildConfiguration> get buildConfigurations => runner.buildConfigurations;
 
   void usesTargetOption() {
@@ -120,7 +122,7 @@
       }
     }
 
-    if (_usesPubOption && argResults['pub']) {
+    if (shouldRunPub) {
       int exitCode = await pubGet();
       if (exitCode != 0)
         return exitCode;