p-hatan/ mirror

pub repository

mirror.p-hatan.ir

cli_util

0.1.4

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

Download archive

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

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.

Changelog

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.ir
flutter pub add cli_util
pubspec.yaml
name: cli_util
version: 0.1.4
author: Dart Team <misc@dartlang.org>
description: A library to help in building Dart command-line apps.
homepage: https://github.com/dart-lang/cli_util

environment:
  sdk: '>=2.0.0 <3.0.0'

dependencies:
  path: '>=1.0.0 <2.0.0'

dev_dependencies:
  test: ^1.0.0

Version history

VersionPublishedArchiveSHA-256
0.0.12015-02-05T22:49:44.635460ZDownloaddacb83104b952b2b3d6edd38d0cdaf2f0bd4908bd0a591b79c8b2333bea491cb
0.0.1+12015-02-10T18:56:22.182090ZDownload8b5e7181b29b8102f5fee3fb706a0929c73195aa17ebb00e3a920d36e0aec7f1
0.0.1+22015-05-19T23:41:58.489110ZDownload979967cb1a84282c822556cab638f73cfdd4dea9f95f763d502dcc5af1bafc73
0.1.02017-05-17T17:23:44.100541ZDownload882c856a6c0e53131215a3fde2a5bef59678cdf7e460ad5d016a46eb3b4ab451
0.1.12017-05-26T18:21:23.446788ZDownload3c0f8a308f089ad7a9d67cd872c3d8aa85d8164d1c0499ae81ee18fbeffef1f7
0.1.22017-07-13T20:05:27.438230ZDownload3f6170537937f38d152900c59121b8319913e246e82ca90b8d837803ca82b80f
0.1.2+12017-09-19T04:28:12.809084ZDownloadbd8c3b607c8eb1d4a4db24560110d47728998831ba40d9e56225c6d5ea54a987
0.1.32018-05-16T21:26:24.033236ZDownload0c92a31faacb3f5d87c517930a14ffbe38a5065c734abdfd283cc14dbfa55856
0.1.3+22018-07-16T22:40:53.318566ZDownload7cfdc9ecb29318940a3c26e6a0e2f802ff7f03e15321d8812f12fa071260b7a3
0.1.42020-05-05T00:33:48.680985ZDownload2573a79aa8032d2c25d615ba7b9e5dcdff1345d68d3209d138ff1ada78f760d7
0.2.02020-06-04T21:19:09.518996ZDownload169b78fc76cf2bb72bab114c6142a20ab7c4ceb7449f8fb8840bb15c9ef1ba27
0.3.0-nullsafety.02020-11-09T18:56:39.169391ZDownload3037a4ebe03c5e2bf64588f00cd5741c1e655404a33ca750fe85e3b94ca3bf04
0.3.02021-02-06T01:16:27.234078ZDownloadcf1c02840bbbcf8fcd13feb5933c62d643cc58ddf4f6088707cf48d1892cbc5d
0.3.12021-06-23T20:49:08.274939ZDownload23f7445806bebabaa27b439f14be85b96e46bd55d0dc83236b6e5d9bd19d2e4b
0.3.22021-07-04T02:20:13.826797ZDownloadf587d416cb2fce97416306b0e20370f1e0d81ebac445c2a849e5473e7f50eade
0.3.32021-07-07T18:15:18.401176ZDownloadcd9cfe046f8b4d87f45abce8f14ec315a4eaedcf92a211e83fa080faf9ec7c1c
0.3.42021-09-30T09:10:20.085322ZDownload58cd69b98a9fca8cf9c3b3df998d6677b2f1f630bee410d2b1d3edf543f1466f
0.3.52021-10-12T09:34:55.408192ZDownload66f86e916d285c1a93d3b79587d94bd71984a66aac4ff74e524cfa7877f1395c
0.4.02023-03-04T23:45:42.181007ZDownloadb8db3080e59b2503ca9e7922c3df2072cf13992354d5e944074ffa836fba43b7
0.4.12023-12-15T19:05:56.300141ZDownloadc05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
0.4.22024-10-29T14:51:14.382638ZDownloadff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
0.5.02026-04-21T09:34:37.444816ZDownload53f32da4e0c381951938e2229e217f3568699e3113463daa382261e0c6fead9e
0.5.12026-05-06T18:28:45.306661ZDownload5909d2c6b66817222779e1eedc19e0e28b76d1df7bd9856a4792ccb9881df358
0.5.22026-07-22T14:41:42.962316ZDownload71e43f1976c3eae2d9468a5b4d6600bf8cae61508b87f27fa1799228935d48ab
0.6.02026-08-21T10:36:16.389260ZDownload89b8801ba49f8b593fbf2d3e59efd0f566c46cd4ba6837ae2610c72b52a0f899

Dependencies

path "\u003e=1.0.0 \u003c2.0.0"