dart-lang/cli_util

Name: cli_util

Owner: Dart

Description: A library to help in building Dart command-line apps

Created: 2015-02-03 18:02:08.0

Updated: 2018-05-16 21:25:53.0

Pushed: 2018-05-16 21:26:41.0

Homepage: https://pub.dartlang.org/packages/cli_util

Size: 34

Language: Dart

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

cli_util

A library to help in building Dart command-line apps.

In particular, cli_util provides a simple, standardized way to get the current SDK directory. Useful, especially, when building client applications that interact with the Dart SDK (such as the analyzer).

Build Status Pub

Locating the Dart SDK
rt 'dart:io';

rt 'package:cli_util/cli_util.dart';
rt 'package:path/path.dart' as path;

(args) {
 Get sdk dir from cli_util.
ring sdkPath = getSdkPath();

 Do stuff... For example, print version string
le versionFile = new File(path.join(sdkPath, 'version'));
int(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:

rt 'package:cli_util/cli_logging.dart';

(List<String> args) async {
ol verbose = args.contains('-v');
gger logger = verbose ? new Logger.verbose() : new Logger.standard();

gger.stdout('Hello world!');
gger.trace('message 1');
ait new Future.delayed(new Duration(milliseconds: 200));
gger.trace('message 2');
gger.trace('message 3');

ogress progress = logger.progress('doing some work');
ait new Future.delayed(new Duration(seconds: 2));
ogress.finish(showTiming: true);

gger.stdout('All ${logger.ansi.emphasized('done')}.');
gger.flush();

Features and bugs

Please file feature requests and bugs at the issue tracker.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.