cli_util

v0.4.2

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

Package archive: https://pubdev.letsnova.ru/api/archives/cli_util/0.4.2.tar.gz

Installdart pub add cli_util

Readme

Build Status Pub package publisher

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 sdkPath getter, deprecate getSdkPath function.
  • Move to dart-lang/tools monorepo.

0.4.1

  • Fix a broken link in the readme.
  • Require Dart 3.0.

0.4.0

  • Remove the deprecated method getSdkDir() (instead, use getSdkPath()).
  • Require Dart 2.19.

0.3.5

  • Make applicationConfigHome throw an Exception when it fails to find a configuration folder.

0.3.4

  • Introduce applicationConfigHome for making it easy to consistently find the user-specific application configuration folder.

0.3.3

  • Reverted meta constraint to ^1.3.0.

0.3.2

  • Update meta constraint to >=1.3.0 <3.0.0.

0.3.1

  • Fix a bug in AnsiProgress where 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.write and Logger.writeCharCode methods which write without printing a trailing newline.

0.1.4

  • Add Ansi.reversed getter.

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