Skip to content

Commit

Permalink
add arguments option for more function
Browse files Browse the repository at this point in the history
  • Loading branch information
moweiran committed Jul 10, 2024
1 parent 08018dd commit f42c5be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.2

- add -c option to clean output files
- add -v option to show log

## 1.3.1

- display log on cmd
Expand Down
34 changes: 30 additions & 4 deletions bin/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:args/command_runner.dart';
const String hostFlag = 'host';
const String tokenFlag = 'token';
const String verboseFlag = 'verbose';
const String cleanFlag = 'clean';

void main(List<String> arguments) {
CommandRunner('json', "A dart implementation of json convert to model")
Expand Down Expand Up @@ -37,13 +38,36 @@ class BuildCommand extends Command {
abbr: 'v',
help: 'Verbose output',
defaultsTo: false,
)
..addFlag(
cleanFlag,
abbr: 'c',
help: 'clean output',
defaultsTo: false,
);
}

@override
FutureOr? run() async {
final host = argResults?['host'] ?? "";
final token = argResults?['token'] ?? "";
// stdout.writeln(argResults?.options.toString());
// stdout.writeln(argResults?.toString());
final String host = argResults?[hostFlag] ?? "";
final String token = argResults?[tokenFlag] ?? "";
final bool verbose = argResults?[verboseFlag] ?? false;
final bool clean = argResults?[cleanFlag] ?? false;
// stdout.writeln('host=$host');
// stdout.writeln('token=$token');
// stdout.writeln('verbose=$verbose');
// stdout.writeln('clean=$clean');

if (clean) {
final cleanResult =
await Process.run('dart', ['run', 'build_runner', 'clean']);
if (verbose) {
stdout.write(cleanResult.stdout);
stderr.write(cleanResult.stderr);
}
}
final result = await Process.run(
'dart',
[
Expand All @@ -57,7 +81,9 @@ class BuildCommand extends Command {
"json_parse_model:json=token=$token"
],
);
stdout.write(result.stdout);
stderr.write(result.stderr);
if (verbose) {
stdout.write(result.stdout);
stderr.write(result.stderr);
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: json_parse_model
description: A package for convert from json to model by http api
version: 1.3.1
version: 1.3.2
repository: https://github.com/moweiran/json_parse_model.git

environment:
Expand Down

0 comments on commit f42c5be

Please sign in to comment.