common.dart 1.37 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'file_system.dart';
6
import 'platform.dart';
7

8 9
const int kDefaultObservatoryPort = 8100;
const int kDefaultDiagnosticPort  = 8101;
10

11 12 13
/// Return the absolute path of the user's home directory
String get homeDirPath {
  if (_homeDirPath == null) {
14 15 16
    _homeDirPath = platform.isWindows
        ? platform.environment['USERPROFILE']
        : platform.environment['HOME'];
17
    if (_homeDirPath != null)
18
      _homeDirPath = fs.path.absolute(_homeDirPath);
19 20 21 22 23
  }
  return _homeDirPath;
}
String _homeDirPath;

24 25 26 27
/// Throw a specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
/// For example: network errors
28 29
void throwToolExit(String message, { int exitCode }) {
  throw new ToolExit(message, exitCode: exitCode );
30 31
}

32 33 34 35 36
/// Specialized exception for expected situations
/// where the tool should exit with a clear message to the user
/// and no stack trace unless the --verbose option is specified.
/// For example: network errors
class ToolExit implements Exception {
37

38
  ToolExit(this.message, { this.exitCode });
39 40 41 42 43 44 45

  final String message;
  final int exitCode;

  @override
  String toString() => "Exception: $message";
}