Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit d206351

Browse files
ntkmenex3
andauthored
Implement --version flag for cli (#53)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent 4396693 commit d206351

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Emit colors as `Value.HslColor` if that internal representation is
66
available.
77

8+
* Add a `--version` flag that will print a `VersionResponse` as JSON, for ease
9+
of human identification.
10+
811
## 1.0.0-beta.10
912

1013
* Support version 1.0.0-beta.12 of the Sass embedded protocol:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and importers.
88
[Dart Sass]: https://sass-lang.com/dart-sass
99
[Embedded Sass protocol]: https://github.com/sass/sass-embedded-protocol/blob/master/README.md#readme
1010

11+
### Usage
12+
13+
- `dart_sass_embedded` starts the compiler and listens on stdin.
14+
- `dart_sass_embedded --version` prints `versionResponse` with `id = 0` in JSON and exits.
15+
1116
### Releases
1217

1318
Binary releases are available from the [GitHub release page]. We recommend that

bin/dart_sass_embedded.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ import 'package:sass_embedded/src/utils.dart';
1919

2020
void main(List<String> args) {
2121
if (args.isNotEmpty) {
22+
if (args.first == "--version") {
23+
var response = Dispatcher.versionResponse();
24+
response.id = 0;
25+
stdout.writeln(
26+
JsonEncoder.withIndent(" ").convert(response.toProto3Json()));
27+
return;
28+
}
29+
2230
stderr.writeln(
2331
"This executable is not intended to be executed with arguments.\n"
2432
"See https://github.com/sass/embedded-protocol#readme for details.");

lib/src/dispatcher.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,10 @@ class Dispatcher {
5757

5858
switch (message.whichMessage()) {
5959
case InboundMessage_Message.versionRequest:
60-
_send(OutboundMessage()
61-
..versionResponse = (OutboundMessage_VersionResponse()
62-
..protocolVersion =
63-
const String.fromEnvironment("protocol-version")
64-
..compilerVersion =
65-
const String.fromEnvironment("compiler-version")
66-
..implementationVersion =
67-
const String.fromEnvironment("implementation-version")
68-
..implementationName = "Dart Sass"
69-
..id = message.versionRequest.id));
60+
var request = message.versionRequest;
61+
var response = versionResponse();
62+
response.id = request.id;
63+
_send(OutboundMessage()..versionResponse = response);
7064
break;
7165

7266
case InboundMessage_Message.compileRequest:
@@ -226,4 +220,14 @@ class Dispatcher {
226220
break;
227221
}
228222
}
223+
224+
/// Creates a [OutboundMessage_VersionResponse]
225+
static OutboundMessage_VersionResponse versionResponse() {
226+
return OutboundMessage_VersionResponse()
227+
..protocolVersion = const String.fromEnvironment("protocol-version")
228+
..compilerVersion = const String.fromEnvironment("compiler-version")
229+
..implementationVersion =
230+
const String.fromEnvironment("implementation-version")
231+
..implementationName = "Dart Sass";
232+
}
229233
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_embedded
2-
version: 1.0.0-dev
2+
version: 1.0.0-beta.11
33
description: An implementation of the Sass embedded protocol using Dart Sass.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass-embedded

0 commit comments

Comments
 (0)