add parse args
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:args/args.dart';
|
||||
|
||||
main(List<String> args) async {
|
||||
final jsonContent = await readContent(args);
|
||||
final parser = new ArgParser();
|
||||
parser.addFlag('help', abbr: 'h', defaultsTo: false, help: 'Help');
|
||||
|
||||
final parseResult = parser.parse(args);
|
||||
if (parseResult['help']) {
|
||||
print('Print help message for prettyjson.dart');
|
||||
return;
|
||||
}
|
||||
|
||||
final restArgs = parseResult.rest;
|
||||
|
||||
final jsonContent = await readContent(restArgs);
|
||||
final jsonDecoded = json.decode(jsonContent);
|
||||
JsonEncoder encoder = new JsonEncoder.withIndent(' ');
|
||||
print(encoder.convert(jsonDecoded));
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
name:
|
||||
prettyjson.dart
|
||||
|
||||
dependencies:
|
||||
args: ^1.5.2
|
||||
|
||||
Reference in New Issue
Block a user