Added show non-printing option.
This commit is contained in:
parent
4948aaa970
commit
9397ebaa37
14 changed files with 316 additions and 298 deletions
|
@ -8,33 +8,43 @@ import 'package:args/args.dart';
|
|||
import 'package:dcat/dcat.dart';
|
||||
import 'package:indent/indent.dart';
|
||||
|
||||
const appName = libName;
|
||||
const appName = 'dcat';
|
||||
const appVersion = '1.0.0';
|
||||
const helpFlag = 'help';
|
||||
const nonBlankFlag = 'number-nonblank';
|
||||
const numberFlag = 'number';
|
||||
const showAllFlag = 'show-all';
|
||||
const showEndsFlag = 'show-ends';
|
||||
const showNonPrintingEndsFlag = 'show-nonprinting-ends';
|
||||
const showNonPrintingFlag = 'show-nonprinting';
|
||||
const showNonPrintingTabsFlag = 'show-nonprinting-tabs';
|
||||
const showTabsFlag = 'show-tabs';
|
||||
const squeezeBlank = 'squeeze-blank';
|
||||
const versionFlag = 'version';
|
||||
|
||||
/// Concatenates files specified in [arguments].
|
||||
///
|
||||
/// Usage: `dcat [OPTION]... [FILE]...`
|
||||
/// 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,
|
||||
negatable: false,
|
||||
abbr: 'b',
|
||||
help: 'number nonempty output lines, overrides -n');
|
||||
parser.addFlag(showNonPrintingEndsFlag,
|
||||
negatable: false, abbr: 'e', help: 'equivalent to -vE');
|
||||
parser.addFlag(showEndsFlag,
|
||||
negatable: false, abbr: 'E', help: 'display \$ at end of each line');
|
||||
parser.addFlag(helpFlag,
|
||||
negatable: false, abbr: 'h', help: 'display this help and exit');
|
||||
parser.addFlag(numberFlag,
|
||||
negatable: false, abbr: 'n', help: 'number all output lines');
|
||||
parser.addFlag(showNonPrintingTabsFlag,
|
||||
negatable: false, abbr: 't', help: 'equivalent to -vT');
|
||||
parser.addFlag(showTabsFlag,
|
||||
negatable: false, abbr: 'T', help: 'display TAB characters as ^I');
|
||||
parser.addFlag(squeezeBlank,
|
||||
|
@ -43,6 +53,11 @@ Future<int> main(List<String> arguments) async {
|
|||
help: 'suppress repeated empty output lines');
|
||||
parser.addFlag(versionFlag,
|
||||
negatable: false, help: 'output version information and exit');
|
||||
parser.addFlag('ignored', negatable: false, hide: true, abbr: 'u');
|
||||
parser.addFlag(showNonPrintingFlag,
|
||||
negatable: false,
|
||||
abbr: 'v',
|
||||
help: 'use ^ and M- notation, except for LFD and TAB');
|
||||
|
||||
final ArgResults argResults;
|
||||
try {
|
||||
|
@ -59,12 +74,30 @@ Future<int> main(List<String> arguments) async {
|
|||
returnCode = printVersion();
|
||||
} else {
|
||||
final paths = argResults.rest;
|
||||
var showEnds = argResults[showEndsFlag];
|
||||
var showTabs = argResults[showTabsFlag];
|
||||
var showNonPrinting = argResults[showNonPrintingFlag];
|
||||
|
||||
if (argResults[showNonPrintingEndsFlag]) {
|
||||
showNonPrinting = showEnds = true;
|
||||
}
|
||||
|
||||
if (argResults[showNonPrintingTabsFlag]) {
|
||||
showNonPrinting = showTabs = true;
|
||||
}
|
||||
|
||||
if (argResults[showAllFlag]) {
|
||||
showNonPrinting = showEnds = showTabs = true;
|
||||
}
|
||||
|
||||
returnCode = cat(paths,
|
||||
showEnds: argResults[showEndsFlag],
|
||||
appName: appName,
|
||||
showEnds: showEnds,
|
||||
showLineNumbers: argResults[numberFlag],
|
||||
numberNonBlank: argResults[nonBlankFlag],
|
||||
showTabs: argResults[showTabsFlag],
|
||||
squeezeBlank: argResults[squeezeBlank]);
|
||||
showTabs: showTabs,
|
||||
squeezeBlank: argResults[squeezeBlank],
|
||||
showNonPrinting: showNonPrinting);
|
||||
}
|
||||
|
||||
exitCode = await returnCode;
|
||||
|
@ -76,7 +109,7 @@ Future<int> printVersion() async {
|
|||
print('''$appName (Dart cat) $appVersion
|
||||
Copyright (C) 2021 Erik C. Thauvin
|
||||
License: 3-Clause BSD <https://opensource.org/licenses/BSD-3-Clause>
|
||||
|
||||
|
||||
Inspired by <https://dart.dev/tutorials/server/cmdline>
|
||||
Written by Erik C. Thauvin <https://erik.thauvin.net/>''');
|
||||
return exitSuccess;
|
||||
|
@ -93,7 +126,7 @@ ${options.indent(2)}
|
|||
Examples:
|
||||
$appName f - g Output f's contents, then standard input, then g's contents.
|
||||
$appName Copy standard input to standard output.
|
||||
|
||||
Source and documentation: <https://github.com/ethauvin/dcat>''');
|
||||
|
||||
Source and documentation: <https://github.com/ethauvin/dcat>''');
|
||||
return exitSuccess;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue