Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Make sdkPath a getter
Browse files Browse the repository at this point in the history
Add `sdkPath` getter and deprecate `getSdkPath` function.
  • Loading branch information
lrhn authored Apr 3, 2024
1 parent 12cd216 commit 143ef58
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions lib/cli_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import 'dart:io';

import 'package:path/path.dart' as path;

/// Return the path to the current Dart SDK.
String getSdkPath() => path.dirname(path.dirname(Platform.resolvedExecutable));
/// The path to the current Dart SDK.
String get sdkPath => path.dirname(path.dirname(Platform.resolvedExecutable));

/// Get the user-specific application configuration folder for the current
/// platform.
/// Returns the path to the current Dart SDK.
@Deprecated("Use 'sdkPath' instead")
String getSdkPath() => sdkPath;

/// The user-specific application configuration folder for the current platform.
///
/// This is a location appropriate for storing application specific
/// configuration for the current user. The [productName] should be unique to
Expand Down Expand Up @@ -70,18 +73,12 @@ String get _configHome {
return path.join(_home, '.config');
}

String get _home {
final home = _env['HOME'];
if (home == null) {
throw EnvironmentNotFoundException(
r'Environment variable $HOME is not defined!');
}
return home;
}
String get _home => _env['HOME'] ?? (throw EnvironmentNotFoundException('HOME'));

class EnvironmentNotFoundException implements Exception {
final String message;
EnvironmentNotFoundException(this.message);
final String entryName;
String get message => 'Environment variable \$$entryName is not defined!';
EnvironmentNotFoundException(this.entryName);
@override
String toString() => message;
}
Expand Down

0 comments on commit 143ef58

Please sign in to comment.