@@ -33,43 +33,18 @@ class ConfigCommand extends BaseCommand {
33
33
final currentConfig = ConfigRepository .loadAppConfig ();
34
34
var updatedConfig = currentConfig;
35
35
36
- // TODO: Consolidate redundant code
37
-
38
- if (wasParsed (ConfigKeys .flutterUrl.paramKey)) {
39
- final flutterRepo = stringArg (ConfigKeys .flutterUrl.paramKey);
40
- logger.info ('Setting flutter repo to: ${yellow .wrap (flutterRepo )}' );
41
- // current.flutterUrl = flutterRepo;
42
- updatedConfig = currentConfig.copyWith (flutterUrl: flutterRepo);
43
- }
44
-
45
- if (wasParsed (ConfigKeys .gitCachePath.paramKey)) {
46
- final gitCachePath = stringArg (ConfigKeys .gitCachePath.paramKey);
47
- logger.info ('Setting git cache path to: ${yellow .wrap (gitCachePath )}' );
48
- // currentConfig.gitCachePath = gitCachePath;
49
- updatedConfig = currentConfig.copyWith (gitCachePath: gitCachePath);
50
- }
51
-
52
- if (wasParsed (ConfigKeys .useGitCache.paramKey)) {
53
- final gitCache = boolArg (ConfigKeys .useGitCache.paramKey);
54
- logger.info (
55
- 'Setting use git cache to: ${yellow .wrap (gitCache .toString ())}' ,
56
- );
57
- updatedConfig = currentConfig.copyWith (useGitCache: gitCache);
58
- }
59
-
60
- if (wasParsed (ConfigKeys .cachePath.paramKey)) {
61
- final cachePath = stringArg (ConfigKeys .cachePath.paramKey);
62
- logger.info ('Setting fvm path to: ${yellow .wrap (cachePath )}' );
63
- updatedConfig = currentConfig.copyWith (cachePath: cachePath);
36
+ void updateConfigKey <T >(ConfigKeys key, T value) {
37
+ if (wasParsed (key.paramKey)) {
38
+ final updatedMap = AppConfig .fromMap ({key.name: value});
39
+ logger.info (
40
+ 'Setting ${key .paramKey } to: ${yellow .wrap (value .toString ())}' ,
41
+ );
42
+ updatedConfig = updatedConfig.merge (updatedMap);
43
+ }
64
44
}
65
45
66
- if (wasParsed (ConfigKeys .priviledgedAccess.paramKey)) {
67
- final priviledgedAccess = boolArg (ConfigKeys .priviledgedAccess.paramKey);
68
- logger.info (
69
- 'Setting priviledged access to: ${yellow .wrap (priviledgedAccess .toString ())}' ,
70
- );
71
- updatedConfig =
72
- currentConfig.copyWith (priviledgedAccess: priviledgedAccess);
46
+ for (var key in ConfigKeys .values) {
47
+ updateConfigKey (key, argResults! [key.paramKey]);
73
48
}
74
49
75
50
// Save
@@ -78,7 +53,7 @@ class ConfigCommand extends BaseCommand {
78
53
final updateProgress = logger.progress ('Saving settings' );
79
54
// Update settings
80
55
try {
81
- ConfigRepository .save (currentConfig );
56
+ ConfigRepository .save (updatedConfig );
82
57
} catch (error) {
83
58
updateProgress.fail ('Failed to save settings' );
84
59
rethrow ;
0 commit comments