Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $ dhttpd --help
--host=<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
6 changes: 6 additions & 0 deletions bin/dhttpd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main(List<String> args) async {
Options options;
Expand All @@ -19,6 +20,11 @@ Future<void> main(List<String> args) async {
return;
}

if (options.version) {
print(packageVersion);
return;
}

await Dhttpd.start(
path: options.path,
port: options.port,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
6 changes: 6 additions & 0 deletions lib/src/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/readme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $ dhttpd --help
--host=<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));
Expand Down