From f47fe99199fdca6fd77da698e3cf8c2bc998fc5f Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 20 Oct 2022 11:49:17 +0200 Subject: [PATCH] feat: add version display supports. --- README.md | 1 + bin/dhttpd.dart | 6 ++++++ lib/src/options.dart | 4 ++++ lib/src/options.g.dart | 6 ++++++ lib/src/version.dart | 2 ++ pubspec.yaml | 1 + test/readme_test.dart | 1 + 7 files changed, 21 insertions(+) create mode 100644 lib/src/version.dart diff --git a/README.md b/README.md index 1bf30ff..41f2a31 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ $ dhttpd --help --host= The hostname to listen on. (defaults to "localhost") -h, --help Displays the help. + --version Prints the version of dhttpd. ``` [path]: https://dart.dev/tools/pub/cmd/pub-global#running-a-script-from-your-path diff --git a/bin/dhttpd.dart b/bin/dhttpd.dart index aad82fb..d449477 100644 --- a/bin/dhttpd.dart +++ b/bin/dhttpd.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:dhttpd/dhttpd.dart'; import 'package:dhttpd/src/options.dart'; +import 'package:dhttpd/src/version.dart'; Future main(List args) async { Options options; @@ -19,6 +20,11 @@ Future main(List args) async { return; } + if (options.version) { + print(packageVersion); + return; + } + await Dhttpd.start( path: options.path, port: options.port, diff --git a/lib/src/options.dart b/lib/src/options.dart index 98957fc..b723932 100644 --- a/lib/src/options.dart +++ b/lib/src/options.dart @@ -31,10 +31,14 @@ class Options { @CliOption(abbr: 'h', negatable: false, help: 'Displays the help.') final bool help; + @CliOption(negatable: false, help: 'Prints the version of dhttpd.') + final bool version; + Options({ required this.port, this.path, required this.host, required this.help, + required this.version, }); } diff --git a/lib/src/options.g.dart b/lib/src/options.g.dart index d0ad260..daf91bf 100644 --- a/lib/src/options.g.dart +++ b/lib/src/options.g.dart @@ -25,6 +25,7 @@ Options _$parseOptionsResult(ArgResults result) => Options( path: result['path'] as String?, host: result['host'] as String, help: result['help'] as bool, + version: result['version'] as bool, ); ArgParser _$populateOptionsParser(ArgParser parser) => parser @@ -51,6 +52,11 @@ ArgParser _$populateOptionsParser(ArgParser parser) => parser abbr: 'h', help: 'Displays the help.', negatable: false, + ) + ..addFlag( + 'version', + help: 'Prints the version of dhttpd.', + negatable: false, ); final _$parserForOptions = _$populateOptionsParser(ArgParser()); diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 0000000..072cbf4 --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1,2 @@ +// Generated code. Do not modify. +const packageVersion = '4.0.2-dev'; diff --git a/pubspec.yaml b/pubspec.yaml index e2771a0..9c9ccc1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,6 +17,7 @@ dev_dependencies: build_cli: ^2.0.2 build_runner: ^2.0.0 build_verify: '>=2.0.0 <4.0.0' + build_version: ^2.1.1 lints: ^1.0.0 path: ^1.6.1 test: ^1.3.0 diff --git a/test/readme_test.dart b/test/readme_test.dart index ae3f36e..4622d08 100644 --- a/test/readme_test.dart +++ b/test/readme_test.dart @@ -29,6 +29,7 @@ $ dhttpd --help --host= The hostname to listen on. (defaults to "localhost") -h, --help Displays the help. + --version Prints the version of dhttpd. ```'''); expect(readme.readAsStringSync(), contains(expected));