cli_util
v0.4.2A library to help in building Dart command-line apps.
Package archive: https://pubdev.letsnova.ru/api/archives/cli_util/0.4.2.tar.gz
Install
dart pub add cli_utilReadme
A package to help in building Dart command-line apps.
What's this?
package:cli_util provides:
- utilities to find the Dart SDK directory (
sdkPath) - utilities to find the settings directory for a tool (
applicationConfigHome()) - utilities to aid in showing rich CLI output and progress information (
cli_logging.dart)
Locating the Dart SDK
import 'dart:io';
import 'package:cli_util/cli_util.dart';
import 'package:path/path.dart' as path;
main(args) {
// Get SDK directory from cli_util.
var sdkDir = sdkPath;
// Do stuff... For example, print version string
var versionFile = File(path.join(sdkDir, 'version'));
print(versionFile.readAsStringSync());
}
Displaying output and progress
package:cli_util can also be used to help CLI tools display output and progress.
It has a logging mechanism which can help differentiate between regular tool
output and error messages, and can facilitate having a more verbose (-v) mode for
output.
In addition, it can display an indeterminate progress spinner for longer running tasks, and optionally display the elapsed time when finished:
import 'package:cli_util/cli_logging.dart';
void main(List<String> args) async {
var verbose = args.contains('-v');
var logger = verbose ? Logger.verbose() : Logger.standard();
logger.stdout('Hello world!');
logger.trace('message 1');
await Future.delayed(Duration(milliseconds: 200));
logger.trace('message 2');
logger.trace('message 3');
var progress = logger.progress('doing some work');
await Future.delayed(Duration(seconds: 2));
progress.finish(showTiming: true);
logger.stdout('All ${logger.ansi.emphasized('done')}.');
logger.flush();
}
Features and bugs
Please file feature requests and bugs at the issue tracker.
Changelog
0.4.2
- Add
sdkPathgetter, deprecategetSdkPathfunction.
- Move to
dart-lang/toolsmonorepo.
0.4.1
- Fix a broken link in the readme.
- Require Dart 3.0.
0.4.0
- Remove the deprecated method
getSdkDir()(instead, usegetSdkPath()). - Require Dart 2.19.
0.3.5
- Make
applicationConfigHomethrow anExceptionwhen it fails to find a configuration folder.
0.3.4
- Introduce
applicationConfigHomefor making it easy to consistently find the user-specific application configuration folder.
0.3.3
- Reverted
metaconstraint to^1.3.0.
0.3.2
- Update
metaconstraint to>=1.3.0 <3.0.0.
0.3.1
- Fix a bug in
AnsiProgresswhere the spinning character doesn't every update.
0.3.0
- Stable null safety release.
0.3.0-nullsafety.0
- Updated to support 2.12.0 and null safety.
0.2.1
0.2.0
- Add
Logger.writeandLogger.writeCharCodemethods which write without printing a trailing newline.
0.1.4
- Add
Ansi.reversedgetter.
0.1.3+2
- Update Dart SDK constraint to < 3.0.0.
0.1.3+1
- Update Dart SDK to 2.0.0-dev.
0.1.3
- In verbose mode, instead of printing the diff from the last log message, print the total time since the tool started
- Change to not buffer the last log message sent in verbose logging mode
- Expose more classes from the logging library
0.1.2+1
- Remove unneeded change to Dart SDK constraint.
0.1.2
- Fix a bug in
getSdkDir(#21)
0.1.1
- Updated to the output for indeterminate progress
- Exposed a
Logger.isVerbosegetter
0.1.0
- Added a new
getSdkPath()method to get the location of the SDK (this uses the newPlatform.resolvedExecutableAPI to locate the SDK) - Deprecated
getSdkDir()in favor ofgetSdkPath() - Add the
cli_logging.dartlibrary - utilities to display output and progress
0.0.1+3
- Find SDK properly when invoked from inside SDK tests.
0.0.1+2
- Support an executable in a symlinked directory.
0.0.1+1
- Fix for when the dart executable can't be found by
which.
0.0.1
- Initial version
