1
+ import 'dart:async' ;
1
2
import 'dart:io' ;
2
- import 'package:path/path.dart' ;
3
- import 'package:intl/intl.dart' ;
4
3
import 'dart:math' ;
5
- import 'package:mime/mime.dart' ;
6
- import 'dart:async' ;
4
+
7
5
import 'package:args/args.dart' ;
6
+ import 'package:intl/intl.dart' ;
7
+ import 'package:mime/mime.dart' ;
8
+ import 'package:path/path.dart' ;
8
9
9
10
part 'constants/ansi.dart' ;
10
11
part 'constants/file_sizes.dart' ;
@@ -36,10 +37,10 @@ void main(List<String> arguments) async {
36
37
// parser.addFlag("recursive", negatable: false, abbr: 'R');
37
38
parser.addFlag ("icons" , negatable: false , abbr: 'I' );
38
39
39
- ArgResults argResults = parser.parse (arguments);
40
+ final ArgResults argResults = parser.parse (arguments);
40
41
41
42
// Read parser flags
42
- Map <String , bool > args = {
43
+ final Map <String , bool > args = {
43
44
'longFileListing' : (argResults["long" ] == true ) ? true : false ,
44
45
'humanReadableFileSize' :
45
46
(argResults["human-readable" ] == true ) ? true : false ,
@@ -53,10 +54,10 @@ void main(List<String> arguments) async {
53
54
54
55
// List all files and directories in the given path, then sort with dirctories on top
55
56
directory = await getPath (argResults);
56
- List <FileSystemEntity > fileList = [];
57
- List <FileSystemEntity > files =
57
+ final List <FileSystemEntity > fileList = [];
58
+ final List <FileSystemEntity > files =
58
59
await listDirectoryContents (directory, type: FileSystemEntityType .file);
59
- List <FileSystemEntity > directories = await listDirectoryContents (
60
+ final List <FileSystemEntity > directories = await listDirectoryContents (
60
61
directory,
61
62
type: FileSystemEntityType .directory,
62
63
);
@@ -71,30 +72,34 @@ void main(List<String> arguments) async {
71
72
displayHeaders (args: args, fileSizeDigits: maxFileSizeLengthInDigits);
72
73
}
73
74
74
- for (FileSystemEntity element in fileList) {
75
+ for (final FileSystemEntity element in fileList) {
75
76
String output = '' ;
76
77
77
- String currentFile = element.uri.toFilePath (windows: Platform .isWindows);
78
+ final String currentFile =
79
+ element.uri.toFilePath (windows: Platform .isWindows);
78
80
79
81
try {
80
- FileStat fileStat = await FileStat .stat (currentFile);
82
+ final FileStat fileStat = await FileStat .stat (currentFile);
81
83
82
84
if (args['longFileListing' ]! ) {
83
85
if (args['showHeaders' ]! ) {
84
86
output += fileType (fileStat);
85
87
output += filePermissions (fileStat);
86
88
87
- output += fileSize (fileStat,
88
- fileSizeDigits: maxFileSizeLengthInDigits ?? 0 , args: args);
89
+ output += fileSize (
90
+ fileStat,
91
+ fileSizeDigits: maxFileSizeLengthInDigits ?? 0 ,
92
+ args: args,
93
+ );
89
94
90
95
output += fileOwner (fileStat);
91
96
output += fileModificationDate (fileStat);
92
97
}
93
98
}
94
99
95
100
if (args['showFileTypeIcon' ]! ) {
96
- String fileToProcess = directory.path + currentFile;
97
- FileSystemEntityType type = fileStat.type;
101
+ final String fileToProcess = directory.path + currentFile;
102
+ final FileSystemEntityType type = fileStat.type;
98
103
output +=
99
104
showFileIcon (fileToProcess, type, headers: args['showHeaders' ]! );
100
105
}
@@ -111,7 +116,7 @@ void main(List<String> arguments) async {
111
116
stderr.write ('$e ' );
112
117
exit (2 );
113
118
} catch (_) {
114
- handleError (currentFile);
119
+ await handleError (currentFile);
115
120
}
116
121
}
117
122
}
0 commit comments