@@ -15,6 +15,11 @@ import '../runner/flutter_command_runner.dart';
1515
1616class ConfigCommand extends FlutterCommand {
1717 ConfigCommand ({ bool verboseHelp = false }) {
18+ argParser.addFlag (
19+ 'list' ,
20+ help: 'List all settings and their current values.' ,
21+ negatable: false ,
22+ );
1823 argParser.addFlag ('analytics' ,
1924 hide: ! verboseHelp,
2025 help: 'Enable or disable reporting anonymously tool usage statistics and crash reports.\n '
@@ -73,37 +78,7 @@ class ConfigCommand extends FlutterCommand {
7378 bool get shouldUpdateCache => false ;
7479
7580 @override
76- String get usageFooter {
77- // List all config settings. for feature flags, include whether they
78- // are available.
79- final Map <String , Feature > featuresByName = < String , Feature > {};
80- final String channel = globals.flutterVersion.channel;
81- for (final Feature feature in allFeatures) {
82- final String ? configSetting = feature.configSetting;
83- if (configSetting != null ) {
84- featuresByName[configSetting] = feature;
85- }
86- }
87- String values = globals.config.keys
88- .map <String >((String key) {
89- String configFooter = '' ;
90- if (featuresByName.containsKey (key)) {
91- final FeatureChannelSetting setting = featuresByName[key]! .getSettingForChannel (channel);
92- if (! setting.available) {
93- configFooter = '(Unavailable)' ;
94- }
95- }
96- return ' $key : ${globals .config .getValue (key )} $configFooter ' ;
97- }).join ('\n ' );
98- if (values.isEmpty) {
99- values = ' No settings have been configured.' ;
100- }
101- final bool analyticsEnabled = globals.flutterUsage.enabled &&
102- ! globals.flutterUsage.suppressAnalytics;
103- return
104- '\n Settings:\n $values \n\n '
105- 'Analytics reporting is currently ${analyticsEnabled ? 'enabled' : 'disabled' }.' ;
106- }
81+ String get usageFooter => '\n $analyticsUsage ' ;
10782
10883 /// Return null to disable analytics recording of the `config` command.
10984 @override
@@ -121,6 +96,11 @@ class ConfigCommand extends FlutterCommand {
12196 ' flutter config --android-studio-dir "/opt/Android Studio"' );
12297 }
12398
99+ if (boolArg ('list' )) {
100+ globals.printStatus (settingsText);
101+ return FlutterCommandResult .success ();
102+ }
103+
124104 if (boolArg ('machine' )) {
125105 await handleMachine ();
126106 return FlutterCommandResult .success ();
@@ -133,6 +113,7 @@ class ConfigCommand extends FlutterCommand {
133113 globals.config.removeValue (configSetting);
134114 }
135115 }
116+ globals.printStatus (requireReloadTipText);
136117 return FlutterCommandResult .success ();
137118 }
138119
@@ -195,7 +176,7 @@ class ConfigCommand extends FlutterCommand {
195176 if (argResults == null || argResults! .arguments.isEmpty) {
196177 globals.printStatus (usage);
197178 } else {
198- globals.printStatus ('\n You may need to restart any open editors for them to read new settings. ' );
179+ globals.printStatus ('\n $ requireReloadTipText ' );
199180 }
200181
201182 return FlutterCommandResult .success ();
@@ -234,4 +215,50 @@ class ConfigCommand extends FlutterCommand {
234215 globals.printStatus ('Setting "$keyName " value to "$keyValue ".' );
235216 }
236217 }
218+
219+ /// List all config settings. for feature flags, include whether they are available.
220+ String get settingsText {
221+ final Map <String , Feature > featuresByName = < String , Feature > {};
222+ final String channel = globals.flutterVersion.channel;
223+ for (final Feature feature in allFeatures) {
224+ final String ? configSetting = feature.configSetting;
225+ if (configSetting != null ) {
226+ featuresByName[configSetting] = feature;
227+ }
228+ }
229+ final Set <String > keys = < String > {
230+ ...allFeatures.map ((Feature e) => e.configSetting).whereType <String >(),
231+ ...globals.config.keys,
232+ };
233+ final Iterable <String > settings = keys.map <String >((String key) {
234+ Object ? value = globals.config.getValue (key);
235+ value ?? = '(Not set)' ;
236+ final StringBuffer buffer = StringBuffer (' $key : $value ' );
237+ if (featuresByName.containsKey (key)) {
238+ final FeatureChannelSetting setting = featuresByName[key]! .getSettingForChannel (channel);
239+ if (! setting.available) {
240+ buffer.write (' (Unavailable)' );
241+ }
242+ }
243+ return buffer.toString ();
244+ });
245+ final StringBuffer buffer = StringBuffer ();
246+ buffer.writeln ('All Settings:' );
247+ if (settings.isEmpty) {
248+ buffer.writeln (' No configs have been configured.' );
249+ } else {
250+ buffer.writeln (settings.join ('\n ' ));
251+ }
252+ return buffer.toString ();
253+ }
254+
255+ /// List the status of the analytics reporting.
256+ String get analyticsUsage {
257+ final bool analyticsEnabled =
258+ globals.flutterUsage.enabled && ! globals.flutterUsage.suppressAnalytics;
259+ return 'Analytics reporting is currently ${analyticsEnabled ? 'enabled' : 'disabled' }.' ;
260+ }
261+
262+ /// Raising the reload tip for setting changes.
263+ final String requireReloadTipText = 'You may need to restart any open editors for them to read new settings.' ;
237264}
0 commit comments