@@ -29,48 +29,56 @@ class ConfigCommand extends BaseCommand {
29
29
@override
30
30
Future <int > run () async {
31
31
// Flag if settings should be saved
32
- var shouldSave = false ;
33
32
34
- var current = ConfigRepository .loadFile ();
33
+ final currentConfig = ConfigRepository .loadAppConfig ();
34
+ var updatedConfig = currentConfig;
35
+
36
+ // TODO: Consolidate redundant code
35
37
36
38
if (wasParsed (ConfigKeys .flutterUrl.paramKey)) {
37
39
final flutterRepo = stringArg (ConfigKeys .flutterUrl.paramKey);
38
40
logger.info ('Setting flutter repo to: ${yellow .wrap (flutterRepo )}' );
39
- current.flutterUrl = flutterRepo;
40
-
41
- shouldSave = true ;
41
+ // current.flutterUrl = flutterRepo;
42
+ updatedConfig = currentConfig.copyWith (flutterUrl: flutterRepo);
42
43
}
43
44
44
45
if (wasParsed (ConfigKeys .gitCachePath.paramKey)) {
45
46
final gitCachePath = stringArg (ConfigKeys .gitCachePath.paramKey);
46
47
logger.info ('Setting git cache path to: ${yellow .wrap (gitCachePath )}' );
47
- current .gitCachePath = gitCachePath;
48
- shouldSave = true ;
48
+ // currentConfig .gitCachePath = gitCachePath;
49
+ updatedConfig = currentConfig. copyWith (gitCachePath : gitCachePath) ;
49
50
}
50
51
51
52
if (wasParsed (ConfigKeys .useGitCache.paramKey)) {
52
53
final gitCache = boolArg (ConfigKeys .useGitCache.paramKey);
53
54
logger.info (
54
55
'Setting use git cache to: ${yellow .wrap (gitCache .toString ())}' ,
55
56
);
56
- current.useGitCache = gitCache;
57
- shouldSave = true ;
57
+ updatedConfig = currentConfig.copyWith (useGitCache: gitCache);
58
58
}
59
59
60
60
if (wasParsed (ConfigKeys .cachePath.paramKey)) {
61
61
final cachePath = stringArg (ConfigKeys .cachePath.paramKey);
62
62
logger.info ('Setting fvm path to: ${yellow .wrap (cachePath )}' );
63
- current.cachePath = cachePath;
64
- shouldSave = true ;
63
+ updatedConfig = currentConfig.copyWith (cachePath: cachePath);
64
+ }
65
+
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);
65
73
}
66
74
67
75
// Save
68
- if (shouldSave ) {
76
+ if (updatedConfig != currentConfig ) {
69
77
logger.info ('' );
70
78
final updateProgress = logger.progress ('Saving settings' );
71
79
// Update settings
72
80
try {
73
- ConfigRepository .save (current );
81
+ ConfigRepository .save (currentConfig );
74
82
} catch (error) {
75
83
updateProgress.fail ('Failed to save settings' );
76
84
rethrow ;
@@ -84,7 +92,7 @@ class ConfigCommand extends BaseCommand {
84
92
..info ('Located at ${ctx .configPath }' )
85
93
..info ('' );
86
94
87
- final options = current .toMap ();
95
+ final options = currentConfig .toMap ();
88
96
89
97
if (options.keys.isEmpty) {
90
98
logger.info ('No settings have been configured.' );
0 commit comments