cli_util 0.1.3+2

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 #

import 'dart:io';

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

main(args) {
  // Get sdk dir from cli_util.
  String sdkPath = getSdkPath();
  
  // Do stuff... For example, print version string
  File versionFile = new File(path.join(sdkPath, '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';

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

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

  Progress progress = logger.progress('doing some work');
  await new Future.delayed(new 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.

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.isVerbose getter

0.1.0 #

  • Added a new getSdkPath() method to get the location of the SDK (this uses the new Platform.resolvedExecutable API to locate the SDK)
  • Deprecated getSdkDir() in favor of getSdkPath()
  • Add the cli_logging.dart library - 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

example/main.dart

// Copyright (c) 2017, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';

import 'package:cli_util/cli_logging.dart';

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

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

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

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  cli_util: ^0.1.3+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:cli_util/cli_util.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
93
Overall:
Weighted score of the above. [more]
89
Learn more about scoring.

We analyzed this package on Jul 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:cli_util/cli_util.dart with components: io.

Health suggestions

Fix lib/cli_logging.dart. (-2.48 points)

Analysis of lib/cli_logging.dart reported 5 hints:

line 70 col 50: Use = to separate a named parameter from its default value.

line 204 col 47: Use = to separate a named parameter from its default value.

line 212 col 20: Use = to separate a named parameter from its default value.

line 213 col 21: Use = to separate a named parameter from its default value.

line 215 col 22: Use = to separate a named parameter from its default value.

Maintenance suggestions

The package description is too short. (-7 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.55.0 <3.0.0
path >=1.0.0 <2.0.0 1.6.2
Dev dependencies
test ^1.0.0

Admin