Skip to content

Commit d7a7e2e

Browse files
authored
Merge pull request #690 from dart-lang/merge-cli_util-package
Merge `package:cli_util`
2 parents c74635e + 5e842b4 commit d7a7e2e

15 files changed

+801
-0
lines changed

.github/ISSUE_TEMPLATE/cli_util.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:cli_util"
3+
about: "Create a bug or file a feature request against package:cli_util."
4+
labels: "package:cli_util"
5+
---

.github/labeler.yml

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
- changed-files:
2525
- any-glob-to-any-file: 'pkgs/cli_config/**'
2626

27+
'package:cli_util':
28+
- changed-files:
29+
- any-glob-to-any-file: 'pkgs/cli_util/**'
30+
2731
'package:clock':
2832
- changed-files:
2933
- any-glob-to-any-file: 'pkgs/clock/**'

.github/workflows/cli_util.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: package:cli_util
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/cli_util.yml'
9+
- 'pkgs/cli_util/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/cli_util.yml'
14+
- 'pkgs/cli_util/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/cli_util/
25+
26+
jobs:
27+
analyze:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
sdk: [dev]
33+
steps:
34+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
35+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
36+
with:
37+
sdk: ${{ matrix.sdk }}
38+
- id: install
39+
name: Install dependencies
40+
run: dart pub get
41+
- name: Check formatting
42+
run: dart format --output=none --set-exit-if-changed .
43+
if: always() && steps.install.outcome == 'success'
44+
- name: Analyze code
45+
run: dart analyze --fatal-infos
46+
if: always() && steps.install.outcome == 'success'
47+
48+
test:
49+
needs: analyze
50+
runs-on: ${{ matrix.os }}
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
os: [ubuntu-latest]
55+
sdk: ['3.4', dev]
56+
steps:
57+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
58+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
59+
with:
60+
sdk: ${{ matrix.sdk }}
61+
- id: install
62+
name: Install dependencies
63+
run: dart pub get
64+
- name: Run tests
65+
run: dart test --test-randomize-ordering-seed=random
66+
if: always() && steps.install.outcome == 'success'

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ don't naturally belong to other topic monorepos (like
1919
| [boolean_selector](pkgs/boolean_selector/) | A flexible syntax for boolean expressions, based on a simplified version of Dart's expression syntax. | [![pub package](https://img.shields.io/pub/v/boolean_selector.svg)](https://pub.dev/packages/boolean_selector) |
2020
| [browser_launcher](pkgs/browser_launcher/) | Provides a standardized way to launch web browsers for testing and tools. | [![pub package](https://img.shields.io/pub/v/browser_launcher.svg)](https://pub.dev/packages/browser_launcher) |
2121
| [cli_config](pkgs/cli_config/) | A library to take config values from configuration files, CLI arguments, and environment variables. | [![pub package](https://img.shields.io/pub/v/cli_config.svg)](https://pub.dev/packages/cli_config) |
22+
| [cli_util](pkgs/cli_util/) | A library to help in building Dart command-line apps. | [![pub package](https://img.shields.io/pub/v/cli_util.svg)](https://pub.dev/packages/cli_util) |
2223
| [clock](pkgs/clock/) | A fakeable wrapper for dart:core clock APIs. | [![pub package](https://img.shields.io/pub/v/clock.svg)](https://pub.dev/packages/clock) |
2324
| [coverage](pkgs/coverage/) | Coverage data manipulation and formatting. | [![pub package](https://img.shields.io/pub/v/coverage.svg)](https://pub.dev/packages/coverage) |
2425
| [csslib](pkgs/csslib/) | A library for parsing and analyzing CSS (Cascading Style Sheets). | [![pub package](https://img.shields.io/pub/v/csslib.svg)](https://pub.dev/packages/csslib) |

pkgs/cli_util/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.dart_tool/
2+
.packages
3+
pubspec.lock

pkgs/cli_util/AUTHORS

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the cli_util project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.

pkgs/cli_util/CHANGELOG.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
## 0.4.2
2+
3+
- Add `sdkPath` getter, deprecate `getSdkPath` function.
4+
* Move to `dart-lang/tools` monorepo.
5+
6+
## 0.4.1
7+
8+
- Fix a broken link in the readme.
9+
- Require Dart 3.0.
10+
11+
## 0.4.0
12+
13+
- Remove the deprecated method `getSdkDir()` (instead, use `getSdkPath()`).
14+
- Require Dart 2.19.
15+
16+
## 0.3.5
17+
- Make `applicationConfigHome` throw an `Exception` when it fails to find a
18+
configuration folder.
19+
20+
## 0.3.4
21+
22+
- Introduce `applicationConfigHome` for making it easy to consistently find the
23+
user-specific application configuration folder.
24+
25+
## 0.3.3
26+
27+
- Reverted `meta` constraint to `^1.3.0`.
28+
29+
## 0.3.2
30+
31+
- Update `meta` constraint to `>=1.3.0 <3.0.0`.
32+
33+
## 0.3.1
34+
35+
- Fix a bug in `AnsiProgress` where the spinning character doesn't every update.
36+
37+
## 0.3.0
38+
39+
- Stable null safety release.
40+
41+
## 0.3.0-nullsafety.0
42+
43+
- Updated to support 2.12.0 and null safety.
44+
45+
## 0.2.1
46+
47+
## 0.2.0
48+
49+
- Add `Logger.write` and `Logger.writeCharCode` methods which write without
50+
printing a trailing newline.
51+
52+
## 0.1.4
53+
54+
- Add `Ansi.reversed` getter.
55+
56+
## 0.1.3+2
57+
58+
- Update Dart SDK constraint to < 3.0.0.
59+
60+
## 0.1.3+1
61+
62+
- Update Dart SDK to 2.0.0-dev.
63+
64+
## 0.1.3
65+
66+
- In verbose mode, instead of printing the diff from the last log message,
67+
print the total time since the tool started
68+
- Change to not buffer the last log message sent in verbose logging mode
69+
- Expose more classes from the logging library
70+
71+
## 0.1.2+1
72+
73+
- Remove unneeded change to Dart SDK constraint.
74+
75+
## 0.1.2
76+
77+
- Fix a bug in `getSdkDir` (#21)
78+
79+
## 0.1.1
80+
81+
- Updated to the output for indeterminate progress
82+
- Exposed a `Logger.isVerbose` getter
83+
84+
## 0.1.0
85+
86+
- Added a new `getSdkPath()` method to get the location of the SDK (this uses the new
87+
`Platform.resolvedExecutable` API to locate the SDK)
88+
- Deprecated `getSdkDir()` in favor of `getSdkPath()`
89+
- Add the `cli_logging.dart` library - utilities to display output and progress
90+
91+
## 0.0.1+3
92+
93+
- Find SDK properly when invoked from inside SDK tests.
94+
95+
## 0.0.1+2
96+
97+
- Support an executable in a symlinked directory.
98+
99+
## 0.0.1+1
100+
101+
- Fix for when the dart executable can't be found by `which`.
102+
103+
## 0.0.1
104+
105+
- Initial version

pkgs/cli_util/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2015, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/cli_util/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/cli_util.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/cli_util.yaml)
2+
[![Pub](https://img.shields.io/pub/v/cli_util.svg)](https://pub.dev/packages/cli_util)
3+
[![package publisher](https://img.shields.io/pub/publisher/cli_util.svg)](https://pub.dev/packages/cli_util/publisher)
4+
5+
A package to help in building Dart command-line apps.
6+
7+
## What's this?
8+
9+
`package:cli_util` provides:
10+
- utilities to find the Dart SDK directory (`sdkPath`)
11+
- utilities to find the settings directory for a tool (`applicationConfigHome()`)
12+
- utilities to aid in showing rich CLI output and progress information (`cli_logging.dart`)
13+
14+
## Locating the Dart SDK
15+
16+
```dart
17+
import 'dart:io';
18+
19+
import 'package:cli_util/cli_util.dart';
20+
import 'package:path/path.dart' as path;
21+
22+
main(args) {
23+
// Get SDK directory from cli_util.
24+
var sdkDir = sdkPath;
25+
26+
// Do stuff... For example, print version string
27+
var versionFile = File(path.join(sdkDir, 'version'));
28+
print(versionFile.readAsStringSync());
29+
}
30+
```
31+
32+
## Displaying output and progress
33+
34+
`package:cli_util` can also be used to help CLI tools display output and progress.
35+
It has a logging mechanism which can help differentiate between regular tool
36+
output and error messages, and can facilitate having a more verbose (`-v`) mode for
37+
output.
38+
39+
In addition, it can display an indeterminate progress spinner for longer running
40+
tasks, and optionally display the elapsed time when finished:
41+
42+
```dart
43+
import 'package:cli_util/cli_logging.dart';
44+
45+
void main(List<String> args) async {
46+
var verbose = args.contains('-v');
47+
var logger = verbose ? Logger.verbose() : Logger.standard();
48+
49+
logger.stdout('Hello world!');
50+
logger.trace('message 1');
51+
await Future.delayed(Duration(milliseconds: 200));
52+
logger.trace('message 2');
53+
logger.trace('message 3');
54+
55+
var progress = logger.progress('doing some work');
56+
await Future.delayed(Duration(seconds: 2));
57+
progress.finish(showTiming: true);
58+
59+
logger.stdout('All ${logger.ansi.emphasized('done')}.');
60+
logger.flush();
61+
}
62+
```
63+
64+
## Features and bugs
65+
66+
Please file feature requests and bugs at the [issue tracker][tracker].
67+
68+
[tracker]: https://github.com/dart-lang/tools/issues

pkgs/cli_util/analysis_options.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://dart.dev/guides/language/analysis-options
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
strict-inference: true
8+
strict-raw-types: true
9+
10+
linter:
11+
rules:
12+
- avoid_bool_literals_in_conditional_expressions
13+
- avoid_classes_with_only_static_members
14+
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
16+
- avoid_returning_this
17+
- avoid_unused_constructor_parameters
18+
- avoid_void_async
19+
- cancel_subscriptions
20+
- join_return_with_assignment
21+
- literal_only_boolean_expressions
22+
- missing_whitespace_between_adjacent_strings
23+
- no_adjacent_strings_in_list
24+
- no_runtimeType_toString
25+
- prefer_const_declarations
26+
- prefer_expression_function_bodies
27+
- prefer_final_locals
28+
- unnecessary_await_in_return
29+
- unnecessary_raw_strings
30+
- use_if_null_to_convert_nulls_to_bools
31+
- use_raw_strings
32+
- use_string_buffers

pkgs/cli_util/example/main.dart

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:cli_util/cli_logging.dart';
8+
9+
Future<void> main(List<String> args) async {
10+
final verbose = args.contains('-v');
11+
final logger = verbose ? Logger.verbose() : Logger.standard();
12+
13+
logger.stdout('Hello world!');
14+
logger.trace('message 1');
15+
await Future<void>.delayed(const Duration(milliseconds: 200));
16+
logger.trace('message 2');
17+
logger.trace('message 3');
18+
19+
final progress = logger.progress('doing some work');
20+
await Future<void>.delayed(const Duration(seconds: 2));
21+
progress.finish(showTiming: true);
22+
23+
logger.stdout('All ${logger.ansi.emphasized('done')}.');
24+
}

0 commit comments

Comments
 (0)