p-hatan/ mirror

pub repository

mirror.p-hatan.com

cli_util

0.4.2

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

Cached in Iran · upstream_checksum

Download archive

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

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add cli_util
pubspec.yaml
name: cli_util
version: 0.4.2
description: A library to help in building Dart command-line apps.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/cli_util

environment:
  sdk: ^3.4.0

dependencies:
  meta: ^1.7.0
  path: ^1.8.0

dev_dependencies:
  dart_flutter_team_lints: ^3.0.0
  test: ^1.20.0

Version history

VersionPublishedArchiveSHA-256
0.0.12015-02-05T22:49:44.635460ZCacheddacb83104b952b2b3d6edd38d0cdaf2f0bd4908bd0a591b79c8b2333bea491cb
0.0.1+12015-02-10T18:56:22.182090ZCached8b5e7181b29b8102f5fee3fb706a0929c73195aa17ebb00e3a920d36e0aec7f1
0.0.1+22015-05-19T23:41:58.489110ZCached979967cb1a84282c822556cab638f73cfdd4dea9f95f763d502dcc5af1bafc73
0.1.02017-05-17T17:23:44.100541ZCached882c856a6c0e53131215a3fde2a5bef59678cdf7e460ad5d016a46eb3b4ab451
0.1.12017-05-26T18:21:23.446788ZCached3c0f8a308f089ad7a9d67cd872c3d8aa85d8164d1c0499ae81ee18fbeffef1f7
0.1.22017-07-13T20:05:27.438230ZCached3f6170537937f38d152900c59121b8319913e246e82ca90b8d837803ca82b80f
0.1.2+12017-09-19T04:28:12.809084ZCachedbd8c3b607c8eb1d4a4db24560110d47728998831ba40d9e56225c6d5ea54a987
0.1.32018-05-16T21:26:24.033236ZCached0c92a31faacb3f5d87c517930a14ffbe38a5065c734abdfd283cc14dbfa55856
0.1.3+22018-07-16T22:40:53.318566ZCached7cfdc9ecb29318940a3c26e6a0e2f802ff7f03e15321d8812f12fa071260b7a3
0.1.42020-05-05T00:33:48.680985ZCached2573a79aa8032d2c25d615ba7b9e5dcdff1345d68d3209d138ff1ada78f760d7
0.2.02020-06-04T21:19:09.518996ZCached169b78fc76cf2bb72bab114c6142a20ab7c4ceb7449f8fb8840bb15c9ef1ba27
0.3.0-nullsafety.02020-11-09T18:56:39.169391ZCached3037a4ebe03c5e2bf64588f00cd5741c1e655404a33ca750fe85e3b94ca3bf04
0.3.02021-02-06T01:16:27.234078ZCachedcf1c02840bbbcf8fcd13feb5933c62d643cc58ddf4f6088707cf48d1892cbc5d
0.3.12021-06-23T20:49:08.274939ZCached23f7445806bebabaa27b439f14be85b96e46bd55d0dc83236b6e5d9bd19d2e4b
0.3.22021-07-04T02:20:13.826797ZCachedf587d416cb2fce97416306b0e20370f1e0d81ebac445c2a849e5473e7f50eade
0.3.32021-07-07T18:15:18.401176ZCachedcd9cfe046f8b4d87f45abce8f14ec315a4eaedcf92a211e83fa080faf9ec7c1c
0.3.42021-09-30T09:10:20.085322ZCached58cd69b98a9fca8cf9c3b3df998d6677b2f1f630bee410d2b1d3edf543f1466f
0.3.52021-10-12T09:34:55.408192ZCached66f86e916d285c1a93d3b79587d94bd71984a66aac4ff74e524cfa7877f1395c
0.4.02023-03-04T23:45:42.181007ZCachedb8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7
0.4.12023-12-15T19:05:56.300141ZCachedc05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
0.4.22024-10-29T14:51:14.382638ZCachedff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
0.5.02026-04-21T09:34:37.444816ZCached53f32da4e0c381951938e2229e217f3568699e3113463daa382261e0c6fead9e
0.5.12026-05-06T18:28:45.306661ZCached5909d2c6b66817222779e1eedc19e0e28b76d1df7bd9856a4792ccb9881df358
0.5.22026-07-22T14:41:42.962316ZCached71e43f1976c3eae2d9468a5b4d6600bf8cae61508b87f27fa1799228935d48ab
0.6.02026-08-21T10:36:16.389260ZCached89b8801ba49f8b593fbf2d3e59efd0f566c46cd4ba6837ae2610c72b52a0f899

Dependencies

meta "^1.7.0"

path "^1.8.0"