• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'file_system.dart';
6import 'platform.dart';
7
8/// Whether the tool started from the daemon, as opposed to the command line.
9// TODO(jonahwilliams): remove once IDE updates have rolled.
10bool isRunningFromDaemon = false;
11
12/// Return the absolute path of the user's home directory
13String get homeDirPath {
14  String path = platform.isWindows
15      ? platform.environment['USERPROFILE']
16      : platform.environment['HOME'];
17  if (path != null) {
18    path = fs.path.absolute(path);
19  }
20  return path;
21}
22
23/// Throw a specialized exception for expected situations
24/// where the tool should exit with a clear message to the user
25/// and no stack trace unless the --verbose option is specified.
26/// For example: network errors
27void throwToolExit(String message, { int exitCode }) {
28  throw ToolExit(message, exitCode: exitCode);
29}
30
31/// Specialized exception for expected situations
32/// where the tool should exit with a clear message to the user
33/// and no stack trace unless the --verbose option is specified.
34/// For example: network errors
35class ToolExit implements Exception {
36  ToolExit(this.message, { this.exitCode });
37
38  final String message;
39  final int exitCode;
40
41  @override
42  String toString() => 'Exception: $message';
43}
44
45/// Indicates to the linter that the given future is intentionally not `await`-ed.
46///
47/// Has the same functionality as `unawaited` from `package:pedantic`.
48///
49/// In an async context, it is normally expected than all Futures are awaited,
50/// and that is the basis of the lint unawaited_futures which is turned on for
51/// the flutter_tools package. However, there are times where one or more
52/// futures are intentionally not awaited. This function may be used to ignore a
53/// particular future. It silences the unawaited_futures lint.
54void unawaited(Future<void> future) { }
55