Implement --version flag for cli (#53)

Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
This commit is contained in:
なつき 2021-09-01 17:33:09 -07:00 committed by GitHub
parent 4396693276
commit d2063513af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 11 deletions

View File

@ -5,6 +5,9 @@
* Emit colors as `Value.HslColor` if that internal representation is
available.
* Add a `--version` flag that will print a `VersionResponse` as JSON, for ease
of human identification.
## 1.0.0-beta.10
* Support version 1.0.0-beta.12 of the Sass embedded protocol:

View File

@ -8,6 +8,11 @@ and importers.
[Dart Sass]: https://sass-lang.com/dart-sass
[Embedded Sass protocol]: https://github.com/sass/sass-embedded-protocol/blob/master/README.md#readme
### Usage
- `dart_sass_embedded` starts the compiler and listens on stdin.
- `dart_sass_embedded --version` prints `versionResponse` with `id = 0` in JSON and exits.
### Releases
Binary releases are available from the [GitHub release page]. We recommend that

View File

@ -19,6 +19,14 @@ import 'package:sass_embedded/src/utils.dart';
void main(List<String> args) {
if (args.isNotEmpty) {
if (args.first == "--version") {
var response = Dispatcher.versionResponse();
response.id = 0;
stdout.writeln(
JsonEncoder.withIndent(" ").convert(response.toProto3Json()));
return;
}
stderr.writeln(
"This executable is not intended to be executed with arguments.\n"
"See https://github.com/sass/embedded-protocol#readme for details.");

View File

@ -57,16 +57,10 @@ class Dispatcher {
switch (message.whichMessage()) {
case InboundMessage_Message.versionRequest:
_send(OutboundMessage()
..versionResponse = (OutboundMessage_VersionResponse()
..protocolVersion =
const String.fromEnvironment("protocol-version")
..compilerVersion =
const String.fromEnvironment("compiler-version")
..implementationVersion =
const String.fromEnvironment("implementation-version")
..implementationName = "Dart Sass"
..id = message.versionRequest.id));
var request = message.versionRequest;
var response = versionResponse();
response.id = request.id;
_send(OutboundMessage()..versionResponse = response);
break;
case InboundMessage_Message.compileRequest:
@ -226,4 +220,14 @@ class Dispatcher {
break;
}
}
/// Creates a [OutboundMessage_VersionResponse]
static OutboundMessage_VersionResponse versionResponse() {
return OutboundMessage_VersionResponse()
..protocolVersion = const String.fromEnvironment("protocol-version")
..compilerVersion = const String.fromEnvironment("compiler-version")
..implementationVersion =
const String.fromEnvironment("implementation-version")
..implementationName = "Dart Sass";
}
}

View File

@ -1,5 +1,5 @@
name: sass_embedded
version: 1.0.0-dev
version: 1.0.0-beta.11
description: An implementation of the Sass embedded protocol using Dart Sass.
author: Sass Team
homepage: https://github.com/sass/dart-sass-embedded