@@ -35,6 +35,35 @@ bool checkDirectoryForWritePermissions(Directory directory) {
3535 return fileStat.modeString ()[1 ] == 'w' ;
3636}
3737
38+ /// Compute whether to suppress analytics based on the environment variable
39+ /// `DASH__SUPPRESS_ANALYTICS` .
40+ ///
41+ /// If the environment variable is set and not "false", return the
42+ /// corresponding boolean value. Otherwise, return the [defaultValue] .
43+ bool computeSuppressAnalytics ({bool defaultValue = false }) =>
44+ bool .fromEnvironment (
45+ DashEnvVar .suppressAnalytics.name,
46+ defaultValue: defaultValue,
47+ );
48+
49+ /// Compute the top-level tool from the environment variable `DASH__TOOL` .
50+ ///
51+ /// If the environment variable is set and valid, return the corresponding
52+ /// [DashTool] . Otherwise, return the [current] tool.
53+ DashTool computeTopLevelTool (DashTool current) {
54+ final toolValue = io.Platform .environment[DashEnvVar .tool.name];
55+ if (toolValue != null ) {
56+ try {
57+ return DashTool .fromLabel (toolValue);
58+ } on Exception {
59+ // Fallback to `current` if the value in ENV is invalid.
60+ // todo(pq): do we need better error handling here?
61+ }
62+ }
63+
64+ return current;
65+ }
66+
3867/// Format time as 'yyyy-MM-dd HH:mm:ss Z' where Z is the difference between the
3968/// timezone of t and UTC formatted according to RFC 822.
4069String formatDateTime (DateTime t) {
0 commit comments