Made cat() a fully standalone library function.
This commit is contained in:
parent
2f996bec48
commit
e1b043c61f
19 changed files with 1182 additions and 271 deletions
49
README.md
49
README.md
|
@ -2,13 +2,13 @@
|
|||
[](https://github.com/ethauvin/dcat/actions/workflows/dart.yml)
|
||||
[](https://codecov.io/gh/ethauvin/dcat)
|
||||
|
||||
# dcat: Concatenate File(s) to Standard Output
|
||||
# dcat: Concatenate File(s) to Standard Output or File
|
||||
|
||||
A **cat** command-line implementation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline).
|
||||
A **cat** command-line and library implementation in [Dart](https://dart.dev/), inspired by the [Write command-line apps sample code](https://dart.dev/tutorials/server/cmdline).
|
||||
|
||||
## Synopsis
|
||||
|
||||
**dcat** copies each file, or standard input if none are given, to standard output.
|
||||
**dcat** copies each file, or standard input if none are given, to standard output or file.
|
||||
|
||||
## Command-Line Usage
|
||||
|
||||
|
@ -49,6 +49,49 @@ dart compile exe -o bin/dcat bin/dcat.dart
|
|||
dart compile exe bin/dcat.dart
|
||||
```
|
||||
|
||||
## Library Usage
|
||||
```dart
|
||||
import 'package:dcat/dcat.dart';
|
||||
|
||||
final result = await cat(['path/to/file', 'path/to/otherfile]'], File('path/to/outfile'));
|
||||
if (result.exitCode == exitFailure) {
|
||||
for (final message in result.messages) {
|
||||
print("Error: $message");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `cat` function supports the following parameters:
|
||||
|
||||
Parameter | Description | Type
|
||||
:--------------- |:----------------------------- | :-------------------
|
||||
paths | The file paths. | String[]
|
||||
output | The standard output or file. | IOSink or File
|
||||
input | The standard input. | Stream<List\<int\>\>?
|
||||
log | The log for debugging. | List\<String\>?
|
||||
showEnds | Same as `-e` | bool
|
||||
numberNonBlank | Same as `-b` | bool
|
||||
showLineNumbers | Same as `-n` | bool
|
||||
showTabs | Same as `-T` | bool
|
||||
squeezeBlank | Same as `-s` | bool
|
||||
showNonPrinting | Same as `-v` | bool
|
||||
|
||||
* `paths` and `output` are required.
|
||||
* `output` should be an `IOSink` like `stdout` or a `File`.
|
||||
* `input` can be `stdin`.
|
||||
* `log` is used for debugging/testing purposes.
|
||||
|
||||
The remaining optional parameters are similar to the [GNU cat](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation) utility.
|
||||
|
||||
A `CatResult` object is returned which contains the `exitCode` (`exitSuccess` or `exitFailure`) and error `messages` if any:
|
||||
|
||||
```dart
|
||||
final result = await cat(['path/to/file'], stdout);
|
||||
if (result.exitCode == exitSuccess) {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Differences from [GNU cat](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation)
|
||||
- No binary file support.
|
||||
- A line is considered terminated by either a `CR` (carriage return), a `LF` (line feed), a `CR+LF` sequence (DOS line ending).
|
||||
|
|
|
@ -27,8 +27,9 @@ const versionFlag = 'version';
|
|||
/// Usage: `dcat [option] [file]…`
|
||||
Future<int> main(List<String> arguments) async {
|
||||
final parser = ArgParser();
|
||||
Future<int> returnCode;
|
||||
|
||||
exitCode = exitSuccess;
|
||||
|
||||
parser.addFlag(showAllFlag,
|
||||
negatable: false, abbr: 'A', help: 'equivalent to -vET');
|
||||
parser.addFlag(nonBlankFlag,
|
||||
|
@ -63,16 +64,14 @@ Future<int> main(List<String> arguments) async {
|
|||
try {
|
||||
argResults = parser.parse(arguments);
|
||||
} on FormatException catch (e) {
|
||||
exitCode = await printError(
|
||||
"${e.message}\nTry '$appName --$helpFlag' for more information.",
|
||||
appName: appName);
|
||||
return exitCode;
|
||||
return printError(
|
||||
"${e.message}\nTry '$appName --$helpFlag' for more information.");
|
||||
}
|
||||
|
||||
if (argResults[helpFlag]) {
|
||||
returnCode = usage(parser.usage);
|
||||
exitCode = await usage(parser.usage);
|
||||
} else if (argResults[versionFlag]) {
|
||||
returnCode = printVersion();
|
||||
exitCode = await printVersion();
|
||||
} else {
|
||||
final paths = argResults.rest;
|
||||
var showEnds = argResults[showEndsFlag];
|
||||
|
@ -91,20 +90,31 @@ Future<int> main(List<String> arguments) async {
|
|||
showNonPrinting = showEnds = showTabs = true;
|
||||
}
|
||||
|
||||
returnCode = cat(paths,
|
||||
appName: appName,
|
||||
final result = await cat(paths, stdout,
|
||||
input: stdin,
|
||||
showEnds: showEnds,
|
||||
showLineNumbers: argResults[numberFlag],
|
||||
numberNonBlank: argResults[nonBlankFlag],
|
||||
showTabs: showTabs,
|
||||
squeezeBlank: argResults[squeezeBlank],
|
||||
showNonPrinting: showNonPrinting);
|
||||
|
||||
for (final message in result.messages) {
|
||||
await printError(message);
|
||||
}
|
||||
|
||||
exitCode = result.exitCode;
|
||||
}
|
||||
|
||||
exitCode = await returnCode;
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
/// Prints the error [message] to [stderr].
|
||||
Future<int> printError(String message) async {
|
||||
stderr.writeln("$appName: $message");
|
||||
return exitFailure;
|
||||
}
|
||||
|
||||
/// Prints the version info.
|
||||
Future<int> printVersion() async {
|
||||
print('''$appName (Dart cat) $appVersion
|
||||
|
|
278
doc/api/dcat/CatResult-class.html
Normal file
278
doc/api/dcat/CatResult-class.html
Normal file
|
@ -0,0 +1,278 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the CatResult class from the dcat library, for the Dart programming language.">
|
||||
<title>CatResult class - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../index.html">dcat</a></li>
|
||||
<li><a href="../dcat/dcat-library.html">dcat</a></li>
|
||||
<li class="self-crumb">CatResult class</li>
|
||||
</ol>
|
||||
<div class="self-name">CatResult</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-class">CatResult</span> class
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
|
||||
</h1></div>
|
||||
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>Holds the <a href="../dcat/cat.html">cat</a> result <a href="../dcat/CatResult/exitCode.html">exitCode</a> and error <a href="../dcat/CatResult/messages.html">messages</a>.</p>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section class="summary offset-anchor" id="constructors">
|
||||
<h2>Constructors</h2>
|
||||
|
||||
<dl class="constructor-summary-list">
|
||||
<dt id="CatResult" class="callable">
|
||||
<span class="name"><a href="../dcat/CatResult/CatResult.html">CatResult</a></span><span class="signature">()</span>
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="summary offset-anchor" id="instance-properties">
|
||||
<h2>Properties</h2>
|
||||
|
||||
<dl class="properties">
|
||||
<dt id="exitCode" class="property">
|
||||
<span class="name"><a href="../dcat/CatResult/exitCode.html">exitCode</a></span>
|
||||
<span class="signature">↔ <a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
The exit code.
|
||||
<div class="features">read / write</div>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="hashCode" class="property inherited">
|
||||
<span class="name"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></span>
|
||||
<span class="signature">→ <a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>
|
||||
|
||||
</dt>
|
||||
<dd class="inherited">
|
||||
The hash code for this object. <a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">[...]</a>
|
||||
<div class="features">read-only, inherited</div>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="messages" class="property">
|
||||
<span class="name"><a href="../dcat/CatResult/messages.html">messages</a></span>
|
||||
<span class="signature">→ <a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span></span>
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
The error messages.
|
||||
<div class="features">final</div>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="runtimeType" class="property inherited">
|
||||
<span class="name"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></span>
|
||||
<span class="signature">→ <a href="https://api.dart.dev/stable/2.14.3/dart-core/Type-class.html">Type</a></span>
|
||||
|
||||
</dt>
|
||||
<dd class="inherited">
|
||||
A representation of the runtime type of the object.
|
||||
<div class="features">read-only, inherited</div>
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="summary offset-anchor" id="instance-methods">
|
||||
<h2>Methods</h2>
|
||||
<dl class="callables">
|
||||
<dt id="addMessage" class="callable">
|
||||
<span class="name"><a href="../dcat/CatResult/addMessage.html">addMessage</a></span><span class="signature">(<wbr><span class="parameter" id="addMessage-param-exitCode"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span> <span class="parameter-name">exitCode</span>, </span><span class="parameter" id="addMessage-param-message"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">message</span>, </span><span class="parameter" id="addMessage-param-path">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a>?</span> <span class="parameter-name">path</span>}</span>)
|
||||
<span class="returntype parameter">→ void</span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
Add a message.
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="noSuchMethod" class="callable inherited">
|
||||
<span class="name"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></span><span class="signature">(<wbr><span class="parameter" id="noSuchMethod-param-invocation"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Invocation-class.html">Invocation</a></span> <span class="parameter-name">invocation</span></span>)
|
||||
<span class="returntype parameter">→ dynamic</span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd class="inherited">
|
||||
Invoked when a non-existent method or property is accessed. <a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">[...]</a>
|
||||
<div class="features">inherited</div>
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="toString" class="callable inherited">
|
||||
<span class="name"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></span><span class="signature">(<wbr>)
|
||||
<span class="returntype parameter">→ <a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd class="inherited">
|
||||
A string representation of this object. <a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">[...]</a>
|
||||
<div class="features">inherited</div>
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section class="summary offset-anchor inherited" id="operators">
|
||||
<h2>Operators</h2>
|
||||
<dl class="callables">
|
||||
<dt id="operator ==" class="callable inherited">
|
||||
<span class="name"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></span><span class="signature">(<wbr><span class="parameter" id="==-param-other"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object-class.html">Object</a></span> <span class="parameter-name">other</span></span>)
|
||||
<span class="returntype parameter">→ <a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd class="inherited">
|
||||
The equality operator. <a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">[...]</a>
|
||||
<div class="features">inherited</div>
|
||||
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../index.html">dcat</a></li>
|
||||
<li><a href="../dcat/dcat-library.html">dcat</a></li>
|
||||
<li class="self-crumb">CatResult class</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
|
||||
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
|
||||
|
||||
|
||||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#constants">Constants</a></li>
|
||||
<li><a href="../dcat/exitFailure-constant.html">exitFailure</a></li>
|
||||
<li><a href="../dcat/exitSuccess-constant.html">exitSuccess</a></li>
|
||||
|
||||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
<ol>
|
||||
|
||||
<li class="section-title"><a href="../dcat/CatResult-class.html#constructors">Constructors</a></li>
|
||||
<li><a href="../dcat/CatResult/CatResult.html">CatResult</a></li>
|
||||
|
||||
|
||||
<li class="section-title">
|
||||
<a href="../dcat/CatResult-class.html#instance-properties">Properties</a>
|
||||
</li>
|
||||
<li><a href="../dcat/CatResult/exitCode.html">exitCode</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></li>
|
||||
<li><a href="../dcat/CatResult/messages.html">messages</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></li>
|
||||
|
||||
<li class="section-title"><a href="../dcat/CatResult-class.html#instance-methods">Methods</a></li>
|
||||
<li><a href="../dcat/CatResult/addMessage.html">addMessage</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></li>
|
||||
|
||||
<li class="section-title inherited"><a href="../dcat/CatResult-class.html#operators">Operators</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
137
doc/api/dcat/CatResult/CatResult.html
Normal file
137
doc/api/dcat/CatResult/CatResult.html
Normal file
|
@ -0,0 +1,137 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the CatResult constructor from the Class CatResult class from the dcat library, for the Dart programming language.">
|
||||
<title>CatResult constructor - CatResult class - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">CatResult constructor</li>
|
||||
</ol>
|
||||
<div class="self-name">CatResult</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-constructor">CatResult</span> constructor
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
</h1></div>
|
||||
|
||||
<section class="multi-line-signature">
|
||||
<span class="name ">CatResult</span>(<wbr>)
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">CatResult();</code></pre>
|
||||
</section>
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">CatResult constructor</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>CatResult class</h5>
|
||||
<ol>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#constructors">Constructors</a></li>
|
||||
<li><a href="../../dcat/CatResult/CatResult.html">CatResult</a></li>
|
||||
|
||||
|
||||
<li class="section-title">
|
||||
<a href="../../dcat/CatResult-class.html#instance-properties">Properties</a>
|
||||
</li>
|
||||
<li><a href="../../dcat/CatResult/exitCode.html">exitCode</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></li>
|
||||
<li><a href="../../dcat/CatResult/messages.html">messages</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></li>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#instance-methods">Methods</a></li>
|
||||
<li><a href="../../dcat/CatResult/addMessage.html">addMessage</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></li>
|
||||
|
||||
<li class="section-title inherited"><a href="../../dcat/CatResult-class.html#operators">Operators</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-left-->
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
155
doc/api/dcat/CatResult/addMessage.html
Normal file
155
doc/api/dcat/CatResult/addMessage.html
Normal file
|
@ -0,0 +1,155 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the addMessage method from the CatResult class, for the Dart programming language.">
|
||||
<title>addMessage method - CatResult class - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">addMessage method</li>
|
||||
</ol>
|
||||
<div class="self-name">addMessage</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-method">addMessage</span> method
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
</h1></div>
|
||||
|
||||
<section class="multi-line-signature">
|
||||
|
||||
|
||||
<span class="returntype">void</span>
|
||||
<span class="name ">addMessage</span>(<wbr><ol class="parameter-list"><li><span class="parameter" id="addMessage-param-exitCode"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span> <span class="parameter-name">exitCode</span>, </span></li>
|
||||
<li><span class="parameter" id="addMessage-param-message"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">message</span>, </span></li>
|
||||
<li><span class="parameter" id="addMessage-param-path">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a>?</span> <span class="parameter-name">path</span>}</span></li>
|
||||
</ol>)
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>Add a message.</p>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">void addMessage(int exitCode, String message, {String? path}) {
|
||||
this.exitCode = exitCode;
|
||||
if (path != null && path.isNotEmpty) {
|
||||
messages.add('$path: $message');
|
||||
} else {
|
||||
messages.add(message);
|
||||
}
|
||||
}</code></pre>
|
||||
</section>
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">addMessage method</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>CatResult class</h5>
|
||||
<ol>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#constructors">Constructors</a></li>
|
||||
<li><a href="../../dcat/CatResult/CatResult.html">CatResult</a></li>
|
||||
|
||||
|
||||
<li class="section-title">
|
||||
<a href="../../dcat/CatResult-class.html#instance-properties">Properties</a>
|
||||
</li>
|
||||
<li><a href="../../dcat/CatResult/exitCode.html">exitCode</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></li>
|
||||
<li><a href="../../dcat/CatResult/messages.html">messages</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></li>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#instance-methods">Methods</a></li>
|
||||
<li><a href="../../dcat/CatResult/addMessage.html">addMessage</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></li>
|
||||
|
||||
<li class="section-title inherited"><a href="../../dcat/CatResult-class.html#operators">Operators</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
143
doc/api/dcat/CatResult/exitCode.html
Normal file
143
doc/api/dcat/CatResult/exitCode.html
Normal file
|
@ -0,0 +1,143 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the exitCode property from the CatResult class, for the Dart programming language.">
|
||||
<title>exitCode property - CatResult class - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">exitCode property</li>
|
||||
</ol>
|
||||
<div class="self-name">exitCode</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-property">exitCode</span> property
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
</h1></div>
|
||||
|
||||
<section class="multi-line-signature">
|
||||
<a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a>
|
||||
<span class="name ">exitCode</span>
|
||||
<div class="features">read / write</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>The exit code.</p>
|
||||
</section>
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">int exitCode = exitSuccess;
|
||||
|
||||
</code></pre>
|
||||
</section>
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">exitCode property</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>CatResult class</h5>
|
||||
<ol>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#constructors">Constructors</a></li>
|
||||
<li><a href="../../dcat/CatResult/CatResult.html">CatResult</a></li>
|
||||
|
||||
|
||||
<li class="section-title">
|
||||
<a href="../../dcat/CatResult-class.html#instance-properties">Properties</a>
|
||||
</li>
|
||||
<li><a href="../../dcat/CatResult/exitCode.html">exitCode</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></li>
|
||||
<li><a href="../../dcat/CatResult/messages.html">messages</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></li>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#instance-methods">Methods</a></li>
|
||||
<li><a href="../../dcat/CatResult/addMessage.html">addMessage</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></li>
|
||||
|
||||
<li class="section-title inherited"><a href="../../dcat/CatResult-class.html#operators">Operators</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
143
doc/api/dcat/CatResult/messages.html
Normal file
143
doc/api/dcat/CatResult/messages.html
Normal file
|
@ -0,0 +1,143 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the messages property from the CatResult class, for the Dart programming language.">
|
||||
<title>messages property - CatResult class - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">messages property</li>
|
||||
</ol>
|
||||
<div class="self-name">messages</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-property">messages</span> property
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
</h1></div>
|
||||
|
||||
<section class="multi-line-signature">
|
||||
<a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span>
|
||||
<span class="name ">messages</span>
|
||||
<div class="features">final</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>The error messages.</p>
|
||||
</section>
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">final List<String> messages = [];
|
||||
|
||||
</code></pre>
|
||||
</section>
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../../index.html">dcat</a></li>
|
||||
<li><a href="../../dcat/dcat-library.html">dcat</a></li>
|
||||
<li><a href="../../dcat/CatResult-class.html">CatResult</a></li>
|
||||
<li class="self-crumb">messages property</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>CatResult class</h5>
|
||||
<ol>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#constructors">Constructors</a></li>
|
||||
<li><a href="../../dcat/CatResult/CatResult.html">CatResult</a></li>
|
||||
|
||||
|
||||
<li class="section-title">
|
||||
<a href="../../dcat/CatResult-class.html#instance-properties">Properties</a>
|
||||
</li>
|
||||
<li><a href="../../dcat/CatResult/exitCode.html">exitCode</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/hashCode.html">hashCode</a></li>
|
||||
<li><a href="../../dcat/CatResult/messages.html">messages</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/runtimeType.html">runtimeType</a></li>
|
||||
|
||||
<li class="section-title"><a href="../../dcat/CatResult-class.html#instance-methods">Methods</a></li>
|
||||
<li><a href="../../dcat/CatResult/addMessage.html">addMessage</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/toString.html">toString</a></li>
|
||||
|
||||
<li class="section-title inherited"><a href="../../dcat/CatResult-class.html#operators">Operators</a></li>
|
||||
<li class="inherited"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object/operator_equals.html">operator ==</a></li>
|
||||
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -52,9 +52,10 @@
|
|||
<section class="multi-line-signature">
|
||||
|
||||
|
||||
<span class="returntype"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>
|
||||
<span class="returntype"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dcat/CatResult-class.html">CatResult</a></span>></span></span>
|
||||
<span class="name ">cat</span>(<wbr><ol class="parameter-list"><li><span class="parameter" id="cat-param-paths"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span></span> <span class="parameter-name">paths</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-appName">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">appName</span> = <span class="default-value">''</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-output"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object-class.html">Object</a></span> <span class="parameter-name">output</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-input">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Stream-class.html">Stream</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>></span>?</span> <span class="parameter-name">input</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-log"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span>?</span> <span class="parameter-name">log</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-showEnds"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showEnds</span> = <span class="default-value">false</span>, </span></li>
|
||||
<li><span class="parameter" id="cat-param-numberNonBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">numberNonBlank</span> = <span class="default-value">false</span>, </span></li>
|
||||
|
@ -67,17 +68,21 @@
|
|||
</section>
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>Concatenates files in <code>paths</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a></p>
|
||||
<p>The parameters are similar to the <a href="https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation">GNU cat utility</a>.
|
||||
Specify a <code>log</code> for debugging or testing purpose.</p>
|
||||
<p>Concatenates files in <code>paths</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> or <a href="https://api.dart.dev/stable/2.14.3/dart-io/File-class.html">File</a>.</p>
|
||||
<ul>
|
||||
<li><code>output</code> should be an <a href="https://api.dart.dev/stable/2.14.3/dart-io/IOSink-class.html">IOSink</a> like <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> or a <a href="https://api.dart.dev/stable/2.14.3/dart-io/File-class.html">File</a>.</li>
|
||||
<li><code>input</code> can be <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdin.html">stdin</a>.</li>
|
||||
<li><code>log</code> is used for debugging/testing purposes.</li>
|
||||
</ul>
|
||||
<p>The remaining optional parameters are similar to the <a href="https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation">GNU cat utility</a>.</p>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">Future<int> cat(List<String> paths,
|
||||
{String appName = '',
|
||||
<pre class="language-dart"><code class="language-dart">Future<CatResult> cat(List<String> paths, Object output,
|
||||
{Stream<List<int>>? input,
|
||||
List<String>? log,
|
||||
bool showEnds = false,
|
||||
bool numberNonBlank = false,
|
||||
|
@ -85,19 +90,34 @@ Specify a <code>log</code> for debugging or testing purpose.</p>
|
|||
bool showTabs = false,
|
||||
bool squeezeBlank = false,
|
||||
bool showNonPrinting = false}) async {
|
||||
var result = CatResult();
|
||||
var lineNumber = 1;
|
||||
var returnCode = 0;
|
||||
log?.clear();
|
||||
if (paths.isEmpty) {
|
||||
final lines = await _readStdin();
|
||||
await _writeLines(lines, lineNumber, log, showEnds, showLineNumbers,
|
||||
numberNonBlank, showTabs, squeezeBlank, showNonPrinting);
|
||||
if (input != null) {
|
||||
final lines = await _readStream(input);
|
||||
try {
|
||||
await _writeLines(
|
||||
lines,
|
||||
lineNumber,
|
||||
output,
|
||||
log,
|
||||
showEnds,
|
||||
showLineNumbers,
|
||||
numberNonBlank,
|
||||
showTabs,
|
||||
squeezeBlank,
|
||||
showNonPrinting);
|
||||
} catch (e) {
|
||||
result.addMessage(exitFailure, '$e');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final path in paths) {
|
||||
try {
|
||||
final Stream<String> lines;
|
||||
if (path == '-') {
|
||||
lines = await _readStdin();
|
||||
if (path == '-' && input != null) {
|
||||
lines = await _readStream(input);
|
||||
} else {
|
||||
lines = utf8.decoder
|
||||
.bind(File(path).openRead())
|
||||
|
@ -106,6 +126,7 @@ Specify a <code>log</code> for debugging or testing purpose.</p>
|
|||
lineNumber = await _writeLines(
|
||||
lines,
|
||||
lineNumber,
|
||||
output,
|
||||
log,
|
||||
showEnds,
|
||||
showLineNumbers,
|
||||
|
@ -121,17 +142,16 @@ Specify a <code>log</code> for debugging or testing purpose.</p>
|
|||
} else {
|
||||
message = e.message;
|
||||
}
|
||||
returnCode = await printError(message, appName: appName, path: path);
|
||||
result.addMessage(exitFailure, message, path: path);
|
||||
} on FormatException {
|
||||
returnCode = await printError('Binary file not supported.',
|
||||
appName: appName, path: path);
|
||||
result.addMessage(exitFailure, 'Binary file not supported.',
|
||||
path: path);
|
||||
} catch (e) {
|
||||
returnCode =
|
||||
await printError(e.toString(), appName: appName, path: path);
|
||||
result.addMessage(exitFailure, '$e', path: path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnCode;
|
||||
return result;
|
||||
}</code></pre>
|
||||
</section>
|
||||
|
||||
|
@ -154,6 +174,8 @@ Specify a <code>log</code> for debugging or testing purpose.</p>
|
|||
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
|
||||
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
|
||||
|
||||
|
||||
|
||||
|
@ -164,7 +186,6 @@ Specify a <code>log</code> for debugging or testing purpose.</p>
|
|||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
<li><a href="../dcat/printError.html">printError</a></li>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -50,10 +50,24 @@
|
|||
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>Library to concatenate file(s) to standard output,</p>
|
||||
<p>A library to concatenate files to standard output or file.</p>
|
||||
</section>
|
||||
|
||||
|
||||
<section class="summary offset-anchor" id="classes">
|
||||
<h2>Classes</h2>
|
||||
|
||||
<dl>
|
||||
<dt id="CatResult">
|
||||
<span class="name "><a href="../dcat/CatResult-class.html">CatResult</a></span>
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
Holds the <a href="../dcat/cat.html">cat</a> result <a href="../dcat/CatResult/exitCode.html">exitCode</a> and error <a href="../dcat/CatResult/messages.html">messages</a>.
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
@ -100,27 +114,14 @@
|
|||
|
||||
<dl class="callables">
|
||||
<dt id="cat" class="callable">
|
||||
<span class="name"><a href="../dcat/cat.html">cat</a></span><span class="signature">(<wbr><span class="parameter" id="cat-param-paths"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span></span> <span class="parameter-name">paths</span>, </span><span class="parameter" id="cat-param-appName">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">appName</span> = <span class="default-value">''</span>, </span><span class="parameter" id="cat-param-log"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span>?</span> <span class="parameter-name">log</span>, </span><span class="parameter" id="cat-param-showEnds"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showEnds</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-numberNonBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">numberNonBlank</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showLineNumbers"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showLineNumbers</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showTabs"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showTabs</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-squeezeBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">squeezeBlank</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showNonPrinting"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showNonPrinting</span> = <span class="default-value">false</span>}</span>)
|
||||
<span class="returntype parameter">→ <a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>
|
||||
<span class="name"><a href="../dcat/cat.html">cat</a></span><span class="signature">(<wbr><span class="parameter" id="cat-param-paths"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span></span> <span class="parameter-name">paths</span>, </span><span class="parameter" id="cat-param-output"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/Object-class.html">Object</a></span> <span class="parameter-name">output</span>, </span><span class="parameter" id="cat-param-input">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Stream-class.html">Stream</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>></span>?</span> <span class="parameter-name">input</span>, </span><span class="parameter" id="cat-param-log"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/List-class.html">List</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span>></span>?</span> <span class="parameter-name">log</span>, </span><span class="parameter" id="cat-param-showEnds"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showEnds</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-numberNonBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">numberNonBlank</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showLineNumbers"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showLineNumbers</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showTabs"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showTabs</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-squeezeBlank"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">squeezeBlank</span> = <span class="default-value">false</span>, </span><span class="parameter" id="cat-param-showNonPrinting"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/bool-class.html">bool</a></span> <span class="parameter-name">showNonPrinting</span> = <span class="default-value">false</span>}</span>)
|
||||
<span class="returntype parameter">→ <a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="../dcat/CatResult-class.html">CatResult</a></span>></span></span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
Concatenates files in <code>paths</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> <a href="../dcat/cat.html">[...]</a>
|
||||
|
||||
|
||||
</dd>
|
||||
|
||||
<dt id="printError" class="callable">
|
||||
<span class="name"><a href="../dcat/printError.html">printError</a></span><span class="signature">(<wbr><span class="parameter" id="printError-param-message"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">message</span>, </span><span class="parameter" id="printError-param-appName">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">appName</span> = <span class="default-value">''</span>, </span><span class="parameter" id="printError-param-path"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">path</span> = <span class="default-value">''</span>}</span>)
|
||||
<span class="returntype parameter">→ <a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>
|
||||
</span>
|
||||
|
||||
|
||||
</dt>
|
||||
<dd>
|
||||
Prints the <code>appName</code>, <code>path</code> and error <code>message</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stderr.html">stderr</a>.
|
||||
Concatenates files in <code>paths</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stdout.html">stdout</a> or <a href="https://api.dart.dev/stable/2.14.3/dart-io/File-class.html">File</a>. <a href="../dcat/cat.html">[...]</a>
|
||||
|
||||
|
||||
</dd>
|
||||
|
@ -157,6 +158,8 @@
|
|||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
|
||||
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
|
||||
|
||||
|
||||
|
||||
|
@ -167,7 +170,6 @@
|
|||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
<li><a href="../dcat/printError.html">printError</a></li>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@
|
|||
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
|
||||
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
|
||||
|
||||
|
||||
|
||||
|
@ -93,7 +95,6 @@
|
|||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
<li><a href="../dcat/printError.html">printError</a></li>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -83,6 +83,8 @@
|
|||
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#classes">Classes</a></li>
|
||||
<li><a href="../dcat/CatResult-class.html">CatResult</a></li>
|
||||
|
||||
|
||||
|
||||
|
@ -93,7 +95,6 @@
|
|||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
<li><a href="../dcat/printError.html">printError</a></li>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable=no">
|
||||
<meta name="description" content="API docs for the printError function from the dcat library, for the Dart programming language.">
|
||||
<title>printError function - dcat library - Dart API</title>
|
||||
|
||||
|
||||
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../static-assets/github.css?v1">
|
||||
<link rel="stylesheet" href="../static-assets/styles.css?v1">
|
||||
<link rel="icon" href="../static-assets/favicon.png?v1">
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
<body data-base-href="../"
|
||||
data-using-base-href="false">
|
||||
|
||||
<div id="overlay-under-drawer"></div>
|
||||
|
||||
<header id="title">
|
||||
<button id="sidenav-left-toggle" type="button"> </button>
|
||||
<ol class="breadcrumbs gt-separated dark hidden-xs">
|
||||
<li><a href="../index.html">dcat</a></li>
|
||||
<li><a href="../dcat/dcat-library.html">dcat</a></li>
|
||||
<li class="self-crumb">printError function</li>
|
||||
</ol>
|
||||
<div class="self-name">printError</div>
|
||||
<form class="search navbar-right" role="search">
|
||||
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
|
||||
<div id="dartdoc-main-content" class="main-content">
|
||||
<div>
|
||||
<h1><span class="kind-function">printError</span> function
|
||||
<a href="https://dart.dev/null-safety" class="feature feature-null-safety" title="Supports the null safety language feature.">Null safety</a>
|
||||
|
||||
</h1></div>
|
||||
|
||||
<section class="multi-line-signature">
|
||||
|
||||
|
||||
<span class="returntype"><a href="https://api.dart.dev/stable/2.14.3/dart-async/Future-class.html">Future</a><span class="signature"><<wbr><span class="type-parameter"><a href="https://api.dart.dev/stable/2.14.3/dart-core/int-class.html">int</a></span>></span></span>
|
||||
<span class="name ">printError</span>(<wbr><ol class="parameter-list"><li><span class="parameter" id="printError-param-message"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">message</span>, </span></li>
|
||||
<li><span class="parameter" id="printError-param-appName">{<span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">appName</span> = <span class="default-value">''</span>, </span></li>
|
||||
<li><span class="parameter" id="printError-param-path"><span class="type-annotation"><a href="https://api.dart.dev/stable/2.14.3/dart-core/String-class.html">String</a></span> <span class="parameter-name">path</span> = <span class="default-value">''</span>}</span></li>
|
||||
</ol>)
|
||||
|
||||
</section>
|
||||
|
||||
<section class="desc markdown">
|
||||
<p>Prints the <code>appName</code>, <code>path</code> and error <code>message</code> to <a href="https://api.dart.dev/stable/2.14.3/dart-io/stderr.html">stderr</a>.</p>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<section class="summary source-code" id="source">
|
||||
<h2><span>Implementation</span></h2>
|
||||
<pre class="language-dart"><code class="language-dart">Future<int> printError(String message,
|
||||
{String appName = '', String path = ''}) async {
|
||||
if (appName.isNotEmpty) {
|
||||
stderr.write('$appName: ');
|
||||
}
|
||||
if (path.isNotEmpty) {
|
||||
stderr.write('$path: ');
|
||||
}
|
||||
stderr.writeln(message);
|
||||
return exitFailure;
|
||||
}</code></pre>
|
||||
</section>
|
||||
|
||||
|
||||
</div> <!-- /.main-content -->
|
||||
|
||||
<div id="dartdoc-sidebar-left" class="sidebar sidebar-offcanvas-left">
|
||||
<header id="header-search-sidebar" class="hidden-l">
|
||||
<form class="search-sidebar" role="search">
|
||||
<input type="text" id="search-sidebar" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
|
||||
</form>
|
||||
</header>
|
||||
|
||||
<ol class="breadcrumbs gt-separated dark hidden-l" id="sidebar-nav">
|
||||
<li><a href="../index.html">dcat</a></li>
|
||||
<li><a href="../dcat/dcat-library.html">dcat</a></li>
|
||||
<li class="self-crumb">printError function</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<h5>dcat library</h5>
|
||||
<ol>
|
||||
|
||||
|
||||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#constants">Constants</a></li>
|
||||
<li><a href="../dcat/exitFailure-constant.html">exitFailure</a></li>
|
||||
<li><a href="../dcat/exitSuccess-constant.html">exitSuccess</a></li>
|
||||
|
||||
|
||||
<li class="section-title"><a href="../dcat/dcat-library.html#functions">Functions</a></li>
|
||||
<li><a href="../dcat/cat.html">cat</a></li>
|
||||
<li><a href="../dcat/printError.html">printError</a></li>
|
||||
|
||||
|
||||
|
||||
</ol>
|
||||
|
||||
</div><!--/.sidebar-offcanvas-left-->
|
||||
|
||||
<div id="dartdoc-sidebar-right" class="sidebar sidebar-offcanvas-right">
|
||||
</div><!--/.sidebar-offcanvas-->
|
||||
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<span class="no-break">
|
||||
dcat
|
||||
1.0.0
|
||||
</span>
|
||||
|
||||
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script src="../static-assets/highlight.pack.js?v1"></script>
|
||||
<script src="../static-assets/script.js?v1"></script>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -45,11 +45,12 @@
|
|||
|
||||
<section class="desc markdown">
|
||||
<p><a href="http://opensource.org/licenses/BSD-3-Clause"><img src="https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square" alt="License (3-Clause BSD)"></a>
|
||||
<a href="https://github.com/ethauvin/dcat/actions/workflows/dart.yml"><img src="https://github.com/ethauvin/dcat/actions/workflows/dart.yml/badge.svg" alt="GitHub CI"></a></p>
|
||||
<h1 id="dcat-concatenate-files-to-standard-output">dcat: Concatenate File(s) to Standard Output</h1>
|
||||
<p>A <strong>cat</strong> command-line implementation in <a href="https://dart.dev/">Dart</a>, inspired by the <a href="https://dart.dev/tutorials/server/cmdline">Write command-line apps sample code</a>.</p>
|
||||
<a href="https://github.com/ethauvin/dcat/actions/workflows/dart.yml"><img src="https://github.com/ethauvin/dcat/actions/workflows/dart.yml/badge.svg" alt="GitHub CI"></a>
|
||||
<a href="https://codecov.io/gh/ethauvin/dcat"><img src="https://codecov.io/gh/ethauvin/dcat/branch/master/graph/badge.svg?token=9PC4K4IZXJ" alt="codecov"></a></p>
|
||||
<h1 id="dcat-concatenate-files-to-standard-output-or-file">dcat: Concatenate File(s) to Standard Output or File</h1>
|
||||
<p>A <strong>cat</strong> command-line and library implementation in <a href="https://dart.dev/">Dart</a>, inspired by the <a href="https://dart.dev/tutorials/server/cmdline">Write command-line apps sample code</a>.</p>
|
||||
<h2 id="synopsis">Synopsis</h2>
|
||||
<p><strong>dcat</strong> copies each file, or standard input if none are given, to standard output.</p>
|
||||
<p><strong>dcat</strong> copies each file, or standard input if none are given, to standard output or file.</p>
|
||||
<h2 id="command-line-usage">Command-Line Usage</h2>
|
||||
<pre class="language-sh"><code class="language-sh">dcat --help
|
||||
</code></pre>
|
||||
|
@ -81,6 +82,31 @@ Examples:
|
|||
<h3 id="windows">Windows</h3>
|
||||
<pre class="language-cmd"><code class="language-cmd">dart compile exe bin/dcat.dart
|
||||
</code></pre>
|
||||
<h2 id="library-usage">Library Usage</h2>
|
||||
<pre class="language-dart"><code class="language-dart">import 'package:dcat/dcat.dart';
|
||||
|
||||
final result = await cat(['path/to/file', 'path/to/otherfile]'], File('path/to/outfile'));
|
||||
if (result.exitCode == exitFailure) {
|
||||
for (final message in result.messages) {
|
||||
print("Error: $message");
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>The <code>cat</code> function supports the following parameters:</p>
|
||||
<table><thead><tr><th style="text-align: left;">Parameter</th><th style="text-align: left;">Description</th><th style="text-align: left;">Type</th></tr></thead><tbody><tr><td style="text-align: left;">paths</td><td style="text-align: left;">The file paths.</td><td style="text-align: left;">String[]</td></tr><tr><td style="text-align: left;">output</td><td style="text-align: left;">The standard output or file.</td><td style="text-align: left;">IOSink or File</td></tr><tr><td style="text-align: left;">input</td><td style="text-align: left;">The standard input.</td><td style="text-align: left;">Stream<List<int>>?</td></tr><tr><td style="text-align: left;">log</td><td style="text-align: left;">The log for debugging.</td><td style="text-align: left;">List<String>?</td></tr><tr><td style="text-align: left;">showEnds</td><td style="text-align: left;">Same as <code>-e</code></td><td style="text-align: left;">bool</td></tr><tr><td style="text-align: left;">numberNonBlank</td><td style="text-align: left;">Same as <code>-b</code></td><td style="text-align: left;">bool</td></tr><tr><td style="text-align: left;">showLineNumbers</td><td style="text-align: left;">Same as <code>-n</code></td><td style="text-align: left;">bool</td></tr><tr><td style="text-align: left;">showTabs</td><td style="text-align: left;">Same as <code>-T</code></td><td style="text-align: left;">bool</td></tr><tr><td style="text-align: left;">squeezeBlank</td><td style="text-align: left;">Same as <code>-s</code></td><td style="text-align: left;">bool</td></tr><tr><td style="text-align: left;">showNonPrinting</td><td style="text-align: left;">Same as <code>-v</code></td><td style="text-align: left;">bool</td></tr></tbody></table>
|
||||
<ul>
|
||||
<li><code>paths</code> and <code>output</code> are required.</li>
|
||||
<li><code>output</code> should be an <code>IOSink</code> like <code>stdout</code> or a <code>File</code>.</li>
|
||||
<li><code>input</code> can be <code>stdin</code>.</li>
|
||||
<li><code>log</code> is used for debugging/testing purposes.</li>
|
||||
</ul>
|
||||
<p>The remaining optional parameters are similar to the <a href="https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation">GNU cat</a> utility.</p>
|
||||
<p>A <code>CatResult</code> object is returned which contains the <code>exitCode</code> (<code>exitSuccess</code> or <code>exitFailure</code>) and error <code>messages</code> if any:</p>
|
||||
<pre class="language-dart"><code class="language-dart">final result = await cat(['path/to/file'], stdout);
|
||||
if (result.exitCode == exitSuccess) {
|
||||
...
|
||||
}
|
||||
</code></pre>
|
||||
<h2 id="differences-from-gnu-cathttpswwwgnuorgsoftwarecoreutilsmanualhtml_nodecat-invocationhtmlcat-invocation">Differences from <a href="https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation">GNU cat</a></h2>
|
||||
<ul>
|
||||
<li>No binary file support.</li>
|
||||
|
@ -98,7 +124,7 @@ Examples:
|
|||
<span class="name"><a href="dcat/dcat-library.html">dcat</a></span>
|
||||
|
||||
</dt>
|
||||
<dd>Library to concatenate file(s) to standard output,
|
||||
<dd>A library to concatenate files to standard output or file.
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
|
|
|
@ -1 +1 @@
|
|||
[{"name":"dcat","qualifiedName":"dcat","href":"dcat/dcat-library.html","type":"library","overriddenDepth":0,"packageName":"dcat"},{"name":"cat","qualifiedName":"dcat.cat","href":"dcat/cat.html","type":"function","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"exitFailure","qualifiedName":"dcat.exitFailure","href":"dcat/exitFailure-constant.html","type":"top-level constant","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"exitSuccess","qualifiedName":"dcat.exitSuccess","href":"dcat/exitSuccess-constant.html","type":"top-level constant","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"printError","qualifiedName":"dcat.printError","href":"dcat/printError.html","type":"function","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}}]
|
||||
[{"name":"dcat","qualifiedName":"dcat","href":"dcat/dcat-library.html","type":"library","overriddenDepth":0,"packageName":"dcat"},{"name":"CatResult","qualifiedName":"dcat.CatResult","href":"dcat/CatResult-class.html","type":"class","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"CatResult","qualifiedName":"dcat.CatResult.CatResult","href":"dcat/CatResult/CatResult.html","type":"constructor","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"CatResult","type":"class"}},{"name":"addMessage","qualifiedName":"dcat.CatResult.addMessage","href":"dcat/CatResult/addMessage.html","type":"method","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"CatResult","type":"class"}},{"name":"exitCode","qualifiedName":"dcat.CatResult.exitCode","href":"dcat/CatResult/exitCode.html","type":"property","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"CatResult","type":"class"}},{"name":"messages","qualifiedName":"dcat.CatResult.messages","href":"dcat/CatResult/messages.html","type":"property","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"CatResult","type":"class"}},{"name":"cat","qualifiedName":"dcat.cat","href":"dcat/cat.html","type":"function","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"exitFailure","qualifiedName":"dcat.exitFailure","href":"dcat/exitFailure-constant.html","type":"top-level constant","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}},{"name":"exitSuccess","qualifiedName":"dcat.exitSuccess","href":"dcat/exitSuccess-constant.html","type":"top-level constant","overriddenDepth":0,"packageName":"dcat","enclosedBy":{"name":"dcat","type":"library"}}]
|
||||
|
|
108
lib/dcat.dart
108
lib/dcat.dart
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
/// Library to concatenate file(s) to standard output,
|
||||
/// A library to concatenate files to standard output or file.
|
||||
library dcat;
|
||||
|
||||
import 'dart:convert';
|
||||
|
@ -11,12 +11,35 @@ import 'dart:io';
|
|||
const exitFailure = 1;
|
||||
const exitSuccess = 0;
|
||||
|
||||
/// Concatenates files in [paths] to [stdout]
|
||||
/// Holds the [cat] result [exitCode] and error [messages].
|
||||
class CatResult {
|
||||
/// The exit code.
|
||||
int exitCode = exitSuccess;
|
||||
/// The error messages.
|
||||
final List<String> messages = [];
|
||||
|
||||
CatResult();
|
||||
|
||||
/// Add a message.
|
||||
void addMessage(int exitCode, String message, {String? path}) {
|
||||
this.exitCode = exitCode;
|
||||
if (path != null && path.isNotEmpty) {
|
||||
messages.add('$path: $message');
|
||||
} else {
|
||||
messages.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Concatenates files in [paths] to [stdout] or [File].
|
||||
///
|
||||
/// The parameters are similar to the [GNU cat utility](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation).
|
||||
/// Specify a [log] for debugging or testing purpose.
|
||||
Future<int> cat(List<String> paths,
|
||||
{String appName = '',
|
||||
/// * [output] should be an [IOSink] like [stdout] or a [File].
|
||||
/// * [input] can be [stdin].
|
||||
/// * [log] is used for debugging/testing purposes.
|
||||
///
|
||||
/// The remaining optional parameters are similar to the [GNU cat utility](https://www.gnu.org/software/coreutils/manual/html_node/cat-invocation.html#cat-invocation).
|
||||
Future<CatResult> cat(List<String> paths, Object output,
|
||||
{Stream<List<int>>? input,
|
||||
List<String>? log,
|
||||
bool showEnds = false,
|
||||
bool numberNonBlank = false,
|
||||
|
@ -24,19 +47,34 @@ Future<int> cat(List<String> paths,
|
|||
bool showTabs = false,
|
||||
bool squeezeBlank = false,
|
||||
bool showNonPrinting = false}) async {
|
||||
var result = CatResult();
|
||||
var lineNumber = 1;
|
||||
var returnCode = 0;
|
||||
log?.clear();
|
||||
if (paths.isEmpty) {
|
||||
final lines = await _readStdin();
|
||||
await _writeLines(lines, lineNumber, log, showEnds, showLineNumbers,
|
||||
numberNonBlank, showTabs, squeezeBlank, showNonPrinting);
|
||||
if (input != null) {
|
||||
final lines = await _readStream(input);
|
||||
try {
|
||||
await _writeLines(
|
||||
lines,
|
||||
lineNumber,
|
||||
output,
|
||||
log,
|
||||
showEnds,
|
||||
showLineNumbers,
|
||||
numberNonBlank,
|
||||
showTabs,
|
||||
squeezeBlank,
|
||||
showNonPrinting);
|
||||
} catch (e) {
|
||||
result.addMessage(exitFailure, '$e');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final path in paths) {
|
||||
try {
|
||||
final Stream<String> lines;
|
||||
if (path == '-') {
|
||||
lines = await _readStdin();
|
||||
if (path == '-' && input != null) {
|
||||
lines = await _readStream(input);
|
||||
} else {
|
||||
lines = utf8.decoder
|
||||
.bind(File(path).openRead())
|
||||
|
@ -45,6 +83,7 @@ Future<int> cat(List<String> paths,
|
|||
lineNumber = await _writeLines(
|
||||
lines,
|
||||
lineNumber,
|
||||
output,
|
||||
log,
|
||||
showEnds,
|
||||
showLineNumbers,
|
||||
|
@ -60,17 +99,16 @@ Future<int> cat(List<String> paths,
|
|||
} else {
|
||||
message = e.message;
|
||||
}
|
||||
returnCode = await printError(message, appName: appName, path: path);
|
||||
result.addMessage(exitFailure, message, path: path);
|
||||
} on FormatException {
|
||||
returnCode = await printError('Binary file not supported.',
|
||||
appName: appName, path: path);
|
||||
result.addMessage(exitFailure, 'Binary file not supported.',
|
||||
path: path);
|
||||
} catch (e) {
|
||||
returnCode =
|
||||
await printError(e.toString(), appName: appName, path: path);
|
||||
result.addMessage(exitFailure, '$e', path: path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnCode;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Parses line with non-printing characters.
|
||||
|
@ -83,7 +121,7 @@ Future<String> _parseNonPrinting(String line, bool showTabs) async {
|
|||
} else if (ch == 127) {
|
||||
sb.write('^?');
|
||||
} else {
|
||||
sb.write('U+' + ch.toRadixString(16).padLeft(4, '0').toUpperCase());
|
||||
sb.write('U+' + ch.toRadixString(16).padLeft(4, '0').toUpperCase());
|
||||
}
|
||||
} else if (ch == 9 && !showTabs) {
|
||||
sb.write('\t');
|
||||
|
@ -96,25 +134,12 @@ Future<String> _parseNonPrinting(String line, bool showTabs) async {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
/// Prints the [appName], [path] and error [message] to [stderr].
|
||||
Future<int> printError(String message,
|
||||
{String appName = '', String path = ''}) async {
|
||||
if (appName.isNotEmpty) {
|
||||
stderr.write('$appName: ');
|
||||
}
|
||||
if (path.isNotEmpty) {
|
||||
stderr.write('$path: ');
|
||||
}
|
||||
stderr.writeln(message);
|
||||
return exitFailure;
|
||||
}
|
||||
|
||||
/// Reads from stdin.
|
||||
Future<Stream<String>> _readStdin() async =>
|
||||
stdin.transform(utf8.decoder).transform(const LineSplitter());
|
||||
/// Reads from stream (stdin, etc.)
|
||||
Future<Stream<String>> _readStream(Stream<List<int>> input) async =>
|
||||
input.transform(utf8.decoder).transform(const LineSplitter());
|
||||
|
||||
/// Writes lines to stdout.
|
||||
Future<int> _writeLines(Stream<String> lines, int lineNumber,
|
||||
Future<int> _writeLines(Stream<String> lines, int lineNumber, Object out,
|
||||
[List<String>? log,
|
||||
bool showEnds = false,
|
||||
bool showLineNumbers = false,
|
||||
|
@ -150,7 +175,16 @@ Future<int> _writeLines(Stream<String> lines, int lineNumber,
|
|||
}
|
||||
|
||||
log?.add(sb.toString());
|
||||
stdout.writeln(sb);
|
||||
|
||||
try {
|
||||
if (out is IOSink) {
|
||||
out.writeln(sb);
|
||||
} else if (out is File) {
|
||||
await out.writeAsString("$sb\n", mode: FileMode.append);
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
return lineNumber;
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ packages:
|
|||
name: _fe_analyzer_shared
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "28.0.0"
|
||||
version: "29.0.0"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.5.0"
|
||||
version: "2.6.0"
|
||||
args:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -49,7 +49,7 @@ packages:
|
|||
name: cli_util
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.4"
|
||||
version: "0.3.5"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: dcat
|
||||
description: Concatenate file(s) to standard output.
|
||||
description: Concatenate file(s) to standard output or file
|
||||
version: 1.0.0
|
||||
homepage: https://github.com/ethauvin/dcat
|
||||
|
||||
|
|
|
@ -2,56 +2,72 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dcat/dcat.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../bin/dcat.dart' as app;
|
||||
|
||||
void main() {
|
||||
final List<String> log = [];
|
||||
int exitCode;
|
||||
final List<String> log = [];
|
||||
final sampleBinary = 'test/test.7z';
|
||||
final sampleFile = 'test/test.txt';
|
||||
final sampleText = 'This is a test';
|
||||
final sourceFile = 'bin/dcat.dart';
|
||||
final tempDir = Directory.systemTemp.createTempSync();
|
||||
|
||||
Stream<List<int>> mockStdin() async* {
|
||||
yield sampleText.codeUnits;
|
||||
}
|
||||
|
||||
File tmpFile() =>
|
||||
File("${tempDir.path}/tmp-${DateTime.now().millisecondsSinceEpoch}.txt");
|
||||
|
||||
tearDownAll(() => tempDir.delete(recursive: true));
|
||||
|
||||
group('app', () {
|
||||
test('Test Help', () async {
|
||||
expect(app.main(['-h']), completion(equals(0)));
|
||||
expect(app.main(['--help']), completion(equals(0)));
|
||||
expect(app.main(['-h']), completion(0));
|
||||
expect(app.main(['--help']), completion(0));
|
||||
exitCode = await app.main(['-h']);
|
||||
expect(exitCode, equals(exitSuccess));
|
||||
expect(exitCode, exitSuccess);
|
||||
});
|
||||
|
||||
test('Test --version', () async {
|
||||
expect(app.main(['--version']), completion(equals(0)));
|
||||
expect(app.main(['--version']), completion(0));
|
||||
exitCode = await app.main(['--version']);
|
||||
expect(exitCode, equals(exitSuccess));
|
||||
expect(exitCode, exitSuccess);
|
||||
});
|
||||
|
||||
test('Test -a', () async {
|
||||
expect(app.main(['-a']), completion(equals(1)));
|
||||
expect(app.main(['-a']), completion(1));
|
||||
exitCode = await app.main(['-a']);
|
||||
expect(exitCode, equals(exitFailure));
|
||||
expect(exitCode, exitFailure);
|
||||
});
|
||||
|
||||
test('Test directory', () async {
|
||||
exitCode = await app.main(['bin']);
|
||||
expect(exitCode, equals(exitFailure));
|
||||
expect(exitCode, exitFailure);
|
||||
});
|
||||
|
||||
test('Test binary', () async {
|
||||
exitCode = await app.main(['test/test.7z']);
|
||||
expect(exitCode, equals(exitFailure));
|
||||
exitCode = await app.main([sampleBinary]);
|
||||
expect(exitCode, exitFailure);
|
||||
});
|
||||
|
||||
test('Test missing file', () async {
|
||||
exitCode = await app.main(['foo']);
|
||||
expect(exitCode, equals(exitFailure), reason: 'foo not found');
|
||||
exitCode = await app.main(['bin/dcat.dart', 'foo']);
|
||||
expect(exitCode, equals(exitFailure), reason: 'one missing file');
|
||||
expect(exitCode, exitFailure, reason: 'foo not found');
|
||||
exitCode = await app.main([sourceFile, 'foo']);
|
||||
expect(exitCode, exitFailure, reason: 'one missing file');
|
||||
});
|
||||
});
|
||||
|
||||
group('lib', () {
|
||||
test('Test cat source', () async {
|
||||
await cat(['bin/dcat.dart'], log: log);
|
||||
await cat([sourceFile], stdout, log: log);
|
||||
expect(log.isEmpty, false, reason: 'log is empty');
|
||||
expect(log.first, startsWith('// Copyright (c)'),
|
||||
reason: 'has copyright');
|
||||
|
@ -59,8 +75,9 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -n source', () async {
|
||||
exitCode = await cat(['bin/dcat.dart'], log: log, showLineNumbers: true);
|
||||
expect(exitCode, 0, reason: 'result code is 0');
|
||||
final result =
|
||||
await cat([sourceFile], stdout, log: log, showLineNumbers: true);
|
||||
expect(result.exitCode, 0, reason: 'result code is 0');
|
||||
expect(log.first, startsWith(' 1 // Copyright (c)'),
|
||||
reason: 'has copyright');
|
||||
expect(log.last, endsWith(' }'), reason: 'last line');
|
||||
|
@ -70,7 +87,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat source test', () async {
|
||||
await cat(['bin/dcat.dart', 'test/test.txt'], log: log);
|
||||
await cat([sourceFile, sampleFile], stdout, log: log);
|
||||
expect(log.length, greaterThan(10), reason: 'more than 10 lines');
|
||||
expect(log.first, startsWith('// Copyright'),
|
||||
reason: 'start with copyright');
|
||||
|
@ -78,7 +95,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -E', () async {
|
||||
await cat(['test/test.txt'], log: log, showEnds: true);
|
||||
await cat([sampleFile], stdout, log: log, showEnds: true);
|
||||
var hasBlank = false;
|
||||
for (final String line in log) {
|
||||
expect(line, endsWith('\$'));
|
||||
|
@ -91,7 +108,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -bE', () async {
|
||||
await cat(['test/test.txt'],
|
||||
await cat([sampleFile], stdout,
|
||||
log: log, numberNonBlank: true, showEnds: true);
|
||||
var hasBlank = false;
|
||||
for (final String line in log) {
|
||||
|
@ -104,7 +121,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -T', () async {
|
||||
await cat(['test/test.txt'], log: log, showTabs: true);
|
||||
await cat([sampleFile], stdout, log: log, showTabs: true);
|
||||
var hasTab = false;
|
||||
for (final String line in log) {
|
||||
if (line.startsWith('^I')) {
|
||||
|
@ -116,7 +133,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -s', () async {
|
||||
await cat(['test/test.txt'], log: log, squeezeBlank: true);
|
||||
await cat([sampleFile], stdout, log: log, squeezeBlank: true);
|
||||
var hasSqueeze = true;
|
||||
var prevLine = 'foo';
|
||||
for (final String line in log) {
|
||||
|
@ -129,19 +146,19 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -A', () async {
|
||||
await cat(['test/test.txt'],
|
||||
await cat([sampleFile], stdout,
|
||||
log: log, showNonPrinting: true, showEnds: true, showTabs: true);
|
||||
expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713\$'));
|
||||
});
|
||||
|
||||
test('Test cat -t', () async {
|
||||
await cat(['test/test.txt'],
|
||||
await cat([sampleFile], stdout,
|
||||
log: log, showNonPrinting: true, showTabs: true);
|
||||
expect(log.last, equals('^I^A^B^C^DU+00A9^?U+0080U+2713'));
|
||||
});
|
||||
|
||||
test('Test cat-Abs', () async {
|
||||
await cat(['test/test.txt'],
|
||||
await cat([sampleFile], stdout,
|
||||
log: log,
|
||||
showNonPrinting: true,
|
||||
showEnds: true,
|
||||
|
@ -158,7 +175,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('Test cat -v', () async {
|
||||
await cat(['test/test.txt'], log: log, showNonPrinting: true);
|
||||
await cat([sampleFile], stdout, log: log, showNonPrinting: true);
|
||||
var hasTab = false;
|
||||
for (final String line in log) {
|
||||
if (line.contains('\t')) {
|
||||
|
@ -170,5 +187,50 @@ void main() {
|
|||
expect(log.last, equals('\t^A^B^C^DU+00A9^?U+0080U+2713'),
|
||||
reason: 'non-printing');
|
||||
});
|
||||
|
||||
test('Test cat to file', () async {
|
||||
final tmp = tmpFile();
|
||||
final result = await cat([sampleFile], tmp, log: log);
|
||||
expect(result.exitCode, exitSuccess, reason: 'result code is success');
|
||||
expect(result.messages.length, 0, reason: 'messages is empty');
|
||||
expect(await tmp.exists(), true, reason: 'tmp file exists');
|
||||
expect(await tmp.length(), greaterThan(0),
|
||||
reason: 'tmp file is not empty');
|
||||
var lines = await tmp.readAsLines();
|
||||
expect(lines.first, startsWith('Lorem'), reason: 'Lorem in first line');
|
||||
expect(lines.last, endsWith('✓'), reason: 'end with checkmark');
|
||||
});
|
||||
|
||||
test('Test cat with file and binary', () async {
|
||||
final tmp = tmpFile();
|
||||
final result = await cat([sampleFile, sampleBinary], tmp, log: log);
|
||||
expect(result.exitCode, exitFailure, reason: 'result code is failure');
|
||||
expect(result.messages.length, 1, reason: 'as one message');
|
||||
expect(result.messages.first, contains('Binary'),
|
||||
reason: 'message contains binary');
|
||||
});
|
||||
|
||||
test('Test empty stdin', () async {
|
||||
final tmp = tmpFile();
|
||||
var result = await cat([], tmp, input: Stream.empty());
|
||||
expect(result.exitCode, exitSuccess, reason: 'cat() is successful');
|
||||
expect(result.messages.length, 0, reason: 'cat() has no message');
|
||||
|
||||
result = await cat(['-'], tmp, input: Stream.empty());
|
||||
expect(result.exitCode, exitSuccess, reason: 'cat(-) is successful');
|
||||
expect(result.messages.length, 0, reason: 'cat(-) no message');
|
||||
});
|
||||
|
||||
test('Test cat with stdin', () async {
|
||||
var tmp = tmpFile();
|
||||
var result = await cat(['-'], tmp, input: mockStdin());
|
||||
expect(result.exitCode, exitSuccess, reason: 'result code is failure');
|
||||
expect(result.messages.length, 0, reason: 'no message');
|
||||
var lines = await tmp.readAsLines();
|
||||
tmp = tmpFile();
|
||||
expect(await tmp.exists(), false, reason: 'tmp file does not exists');
|
||||
result = await cat([], tmp, input: mockStdin());
|
||||
expect(lines.first, equals(sampleText), reason: 'cat() is sample text');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
BIN
test/test.7z
BIN
test/test.7z
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue