Skip to content

Commit f81b946

Browse files
committed
Released 6.0.0-alpha.1.
1 parent 9fb0464 commit f81b946

28 files changed

+211
-194
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 6.0.0-alpha.1
2+
- moved to the alpha version of dcli 4.x
3+
14
# 5.3.2
25
- upgraded dcli to fix a null check.
36

bin/dswitch.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'package:path/path.dart';
1919

2020
late final CommandRunner<void> runner;
2121
Future<void> main(List<String> args) async {
22-
firstRun();
22+
await firstRun();
2323
runner = buildCommandRunner();
2424
try {
2525
await doit(args);

bin/dswitch_install.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Written by Brett Sutton <[email protected]>, Jan 2022
66
*/
77

8-
import 'dart:io';
8+
import 'dart:io' as io;
99

1010
import 'package:args/args.dart';
1111
import 'package:dcli/dcli.dart';
@@ -18,14 +18,14 @@ import 'package:dswitch/src/settings.dart';
1818
import 'package:path/path.dart';
1919
import 'package:pubspec_manager/pubspec_manager.dart';
2020

21-
void main(List<String> args) {
21+
void main(List<String> args) async {
2222
final argParser = ArgParser()
2323
..addFlag('verbose',
2424
abbr: 'v', negatable: false, help: 'Dump verbose logging information')
2525
..addOption('stage2', help: 'Stage 2', hide: true)
2626
..addOption('home', help: 'Users home directory.', hide: true);
2727
try {
28-
run(args, argParser);
28+
await run(args, argParser);
2929
} on ExitException catch (e) {
3030
String message;
3131
if (e.code == 0) {
@@ -40,7 +40,7 @@ void main(List<String> args) {
4040
}
4141
}
4242

43-
void run(List<String> args, ArgParser argParser) {
43+
Future<void> run(List<String> args, ArgParser argParser) async {
4444
final ArgResults parsed;
4545
try {
4646
parsed = argParser.parse(args);
@@ -52,11 +52,11 @@ void run(List<String> args, ArgParser argParser) {
5252

5353
if (!parsed.wasParsed('stage2')) {
5454
runStage1();
55-
installDart();
55+
await installDart();
5656
} else {
5757
final pathToDSwitch = parsed['stage2'] as String;
5858
final pathToHome = parsed['home'] as String;
59-
runStage2(pathToDSwitch, pathToHome: pathToHome);
59+
await runStage2(pathToDSwitch, pathToHome: pathToHome);
6060

6161
throw ExitException(0, 'Stage2 Completed successfully', showUsage: false);
6262
}
@@ -66,7 +66,7 @@ void run(List<String> args, ArgParser argParser) {
6666

6767
void runStage1() {
6868
if (!Shell.current.isPrivilegedUser) {
69-
if (Platform.isWindows) {
69+
if (io.Platform.isWindows) {
7070
throw ExitException(
7171
1, 'Please run dswitch_install with Administrative privileges.',
7272
showUsage: false);
@@ -119,7 +119,7 @@ void runStage1() {
119119
// join(compileDir, '${script.basename}2${extension(script.basename)}');
120120
// copy(script.pathToExe, duplicate, overwrite: true);
121121

122-
if (!Platform.isWindows) {
122+
if (!io.Platform.isWindows) {
123123
print(green('Please provide your sudo password so we can install '
124124
'dswitch into your PATH'));
125125
}
@@ -156,7 +156,8 @@ void hackPubspecForDev(String pathToDSwitch, String compileDir) {
156156
}
157157

158158
/// In stage 2 we are running from a compiled exe as a privilged user.
159-
void runStage2(String pathToDSwitch, {required String pathToHome}) {
159+
Future<void> runStage2(String pathToDSwitch,
160+
{required String pathToHome}) async {
160161
final target = pathToInstallDir;
161162

162163
if (!exists(pathToDSwitch)) {
@@ -176,7 +177,7 @@ void runStage2(String pathToDSwitch, {required String pathToHome}) {
176177
// that dswtich can check its running the current
177178
// version each time it starts.
178179
Shell.current.releasePrivileges();
179-
updateVersionNo(pathToHome);
180+
await updateVersionNo(pathToHome);
180181
print('');
181182
}
182183

@@ -200,7 +201,7 @@ void removeOldDSwitch() {
200201

201202
String get pathToInstallDir {
202203
String target;
203-
if (Platform.isWindows) {
204+
if (io.Platform.isWindows) {
204205
target = join(
205206
env['USERPROFILE']!, 'AppData', 'Local', 'Microsoft', 'WindowsApps');
206207
} else {
@@ -209,7 +210,7 @@ String get pathToInstallDir {
209210
return target;
210211
}
211212

212-
void installDart() {
213+
Future<void> installDart() async {
213214
Channel? active;
214215

215216
/// Check we have an installed and active version of art.
@@ -222,8 +223,8 @@ void installDart() {
222223

223224
/// if we don't have an active version then install and make it active.
224225
if (active == null) {
225-
Channel('stable')
226-
..installLatestVersion()
227-
..use();
226+
final channel = Channel('stable');
227+
await channel.installLatestVersion();
228+
channel.use();
228229
}
229230
}

lib/src/channel.dart

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ class Channel {
4343
}
4444
}
4545

46-
void installLatestVersion() {
46+
Future<void> installLatestVersion() async {
4747
if (isDownloaded()) {
4848
print(orange('Channel is already installed and the current version is: '
4949
'$currentVersion'));
5050
} else {
51-
final releases = Release.fetchReleases(name);
51+
final releases = await Release.fetchReleases(name);
5252
final version = releases[0].version.toString();
5353
print('Installing $name ($version) ...');
54-
download(version);
55-
currentVersion = version;
54+
await download(version);
55+
await setCurrentVersion(version);
5656
_createChannelSymlink();
5757
print('Install of $name channel complete.');
5858
}
@@ -65,9 +65,9 @@ class Channel {
6565
_createChannelSymlink();
6666
}
6767

68-
void pin(String version) {
69-
currentVersion = version;
70-
pinned = true;
68+
Future<void> pin(String version) async {
69+
await setCurrentVersion(version);
70+
await setPinned(pinned: true);
7171

7272
/// If we are the active channel then we need to update the active link.
7373
if (isActive) {
@@ -76,9 +76,9 @@ class Channel {
7676
_createChannelSymlink();
7777
}
7878

79-
void unpin() {
80-
currentVersion = latestVersion;
81-
pinned = false;
79+
Future<void> unpin() async {
80+
await setCurrentVersion(latestVersion);
81+
await setPinned(pinned: false);
8282

8383
/// If we are the active channel then we need to update the active link.
8484
if (isActive) {
@@ -155,14 +155,14 @@ class Channel {
155155
/// been downloaded.
156156
bool isDownloaded() => isVersionCached(currentVersion);
157157

158-
void download(String version) {
159-
DownloadVersion(name, version, _pathToVersion(version)).download();
158+
Future<void> download(String version) async {
159+
await DownloadVersion(name, version, _pathToVersion(version)).download();
160160
}
161161

162162
/// Downloads the list of versions available for this channel
163163
/// and returns the must recent version.
164-
String fetchLatestVersion() {
165-
final releases = Release.fetchReleases(name);
164+
Future<String> fetchLatestVersion() async {
165+
final releases = await Release.fetchReleases(name);
166166
return releases[0].version.toString();
167167
}
168168

@@ -174,10 +174,9 @@ class Channel {
174174
return _version ??= latestVersion;
175175
}
176176

177-
set currentVersion(String version) {
177+
Future<void> setCurrentVersion(String version) async {
178178
_settings['currentVersion'] = version;
179-
// ignore: discarded_futures
180-
waitForEx(_settings.save());
179+
await _settings.save();
181180
}
182181

183182
/// the most recent version we have downloaded.
@@ -192,10 +191,10 @@ class Channel {
192191
/// If true then this channel is currently pinned.
193192
bool get pinned => _settings['pinned'] as bool? ?? false;
194193

195-
set pinned(bool pinned) {
194+
Future<void> setPinned({required bool pinned}) async {
196195
_settings['pinned'] = pinned;
197196
// ignore: discarded_futures
198-
waitForEx(_settings.save());
197+
await _settings.save();
199198
}
200199

201200
static String channelPath(String channel) =>
@@ -217,8 +216,8 @@ class Channel {
217216
/// Shows the user a menu with the 20 most recent version for the channel.
218217
///
219218
/// Returns the version the user selected.
220-
Release selectToInstall() {
221-
final releases = Release.fetchReleases(name);
219+
Future<Release> selectToInstall() async {
220+
final releases = await Release.fetchReleases(name);
222221

223222
final release = menu<Release>('Select Version to install:',
224223
options: releases,
@@ -242,21 +241,21 @@ class Channel {
242241
bool isVersionCached(String version) =>
243242
cachedVersions().any((element) => basename(element) == version);
244243

245-
void upgrade() {
244+
Future<void> upgrade() async {
246245
if (isPinned) {
247246
printerr(
248247
red('The $name is pinned. Unpin the channel first and try again'));
249248
} else {
250-
final version = fetchLatestVersion();
249+
final version = await fetchLatestVersion();
251250

252251
if (version == currentVersion) {
253252
print('You are already on the latest version ($version) for the '
254253
'$name channel');
255254
} else {
256255
print('Downloading $version...');
257-
download(version);
256+
await download(version);
258257

259-
currentVersion = version;
258+
await setCurrentVersion(version);
260259

261260
if (isActive) {
262261
/// if we are the active channel then calling swithTo

lib/src/commands/channel/install.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ If you pass the --select switch then a menu is displayed with the version availa
2929
String get name => 'install';
3030

3131
@override
32-
void run() {
32+
Future<void> run() async {
3333
checkIsFullyInstalled();
3434
if (argResults!.wasParsed('select')) {
35-
select();
35+
await select();
3636
} else {
3737
if (argResults!.rest.isNotEmpty) {
3838
if (argResults!.rest.length != 1) {
@@ -45,38 +45,38 @@ If you pass the --select switch then a menu is displayed with the version availa
4545
}
4646

4747
final version = argResults!.rest[0];
48-
installVersion(version);
48+
await installVersion(version);
4949
} else {
50-
installLatestVersion(channel);
50+
await installLatestVersion(channel);
5151
}
5252
}
5353
}
5454

55-
void installLatestVersion(String channel) {
56-
Channel(channel).installLatestVersion();
55+
Future<void> installLatestVersion(String channel) async {
56+
await Channel(channel).installLatestVersion();
5757
}
5858

59-
void select() {
59+
Future<void> select() async {
6060
final ch = Channel(channel);
6161

62-
final selected = ch.selectToInstall();
62+
final selected = await ch.selectToInstall();
6363

6464
if (ch.isVersionCached(selected.version.toString())) {
6565
print(blue('The selected version is already installed.'));
6666
} else {
67-
ch.download(selected.version.toString());
67+
await ch.download(selected.version.toString());
6868
}
6969
print('Install of $channel channel complete.');
7070
}
7171

72-
void installVersion(String version) {
72+
Future<void> installVersion(String version) async {
7373
print('Installing $channel version $version...');
7474
final ch = Channel(channel);
7575
if (ch.isVersionCached(version)) {
7676
throw ExitException(1, 'The selected version is already installed.',
7777
showUsage: false);
7878
}
79-
ch.download(version);
79+
await ch.download(version);
8080
print('Install of $channel channel complete. ');
8181
}
8282
}

lib/src/commands/channel/list.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ class ListCommand extends Command<void> {
2828
String get name => 'list';
2929

3030
@override
31-
void run() {
31+
Future<void> run() async {
3232
final showArchives = argResults!.wasParsed('archive');
3333

34-
listForChannel(channel, showArchives: showArchives);
34+
await listForChannel(channel, showArchives: showArchives);
3535
}
3636

37-
static void listForChannel(String channel, {required bool showArchives}) {
37+
static Future<void> listForChannel(String channel,
38+
{required bool showArchives}) async {
3839
final ch = Channel(channel);
3940

4041
print('');
4142
print(green('Channel $channel'));
4243
if (showArchives) {
43-
final releases = Release.fetchReleases(channel);
44+
final releases = await Release.fetchReleases(channel);
4445

4546
print('Available to download:');
4647

lib/src/commands/channel/pin.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Selects the given version for the $channel channel and makes it the active versi
3131
String get name => 'pin';
3232

3333
@override
34-
void run() {
34+
Future<void> run() async {
3535
checkIsFullyInstalled();
3636
String version;
3737

@@ -49,23 +49,24 @@ Selects the given version for the $channel channel and makes it the active versi
4949

5050
version = argResults!.rest[0];
5151
} else {
52-
version = ch.selectToInstall().version.toString();
52+
final release = await ch.selectToInstall();
53+
version = release.version.toString();
5354
}
5455

5556
final force = argResults!['force'] as bool;
5657

5758
if (!ch.isVersionCached(version)) {
5859
printerr(red("\nVersion $version isn't installed.\n"));
5960
if (force || confirm('Install $version')) {
60-
installVersion(version);
61+
await installVersion(version);
6162
} else {
6263
throw ExitException(
6364
0, 'To install $version Use: dswitch $channel install $version\n',
6465
showUsage: false);
6566
}
6667
}
6768

68-
ch.pin(version);
69+
await ch.pin(version);
6970
print(green('Channel $channel is now pinned to $version'));
7071

7172
if (!ch.isActive) {
@@ -81,8 +82,8 @@ Selects the given version for the $channel channel and makes it the active versi
8182
// }
8283
}
8384

84-
void installVersion(String version) {
85+
Future<void> installVersion(String version) async {
8586
print('Installing $channel version $version...');
86-
Channel(channel).download(version);
87+
await Channel(channel).download(version);
8788
}
8889
}

0 commit comments

Comments
 (0)