cli_util 0.1.2+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 97

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.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')}.');
  logger.flush();
}

1. Depend on it

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


dependencies:
  cli_util: "^0.1.2+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages 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';
        
Version Uploaded Documentation Archive
0.1.2+1 Sep 19, 2017 Go to the documentation of cli_util 0.1.2+1 Download cli_util 0.1.2+1 archive
0.1.2 Jul 13, 2017 Go to the documentation of cli_util 0.1.2 Download cli_util 0.1.2 archive
0.1.1 May 26, 2017 Go to the documentation of cli_util 0.1.1 Download cli_util 0.1.1 archive
0.1.0 May 17, 2017 Go to the documentation of cli_util 0.1.0 Download cli_util 0.1.0 archive
0.0.1+2 May 19, 2015 Go to the documentation of cli_util 0.0.1+2 Download cli_util 0.0.1+2 archive
0.0.1+1 Feb 10, 2015 Go to the documentation of cli_util 0.0.1+1 Download cli_util 0.0.1+1 archive
0.0.1 Feb 5, 2015 Go to the documentation of cli_util 0.0.1 Download cli_util 0.0.1 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
95 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
97
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

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

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.11.0 <2.0.0
path >=1.0.0 <2.0.0 1.5.1
Dev dependencies
test ^0.12.0