Add --json-help argument
Add a hidden `--json-help` argument which writes the usage information
in JSON Schema format.
diff --git a/pkgs/test_core/lib/src/executable.dart b/pkgs/test_core/lib/src/executable.dart
index eeefd16..62e0ff1 100644
--- a/pkgs/test_core/lib/src/executable.dart
+++ b/pkgs/test_core/lib/src/executable.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
+import 'dart:convert';
import 'dart:io';
import 'package:async/async.dart';
@@ -81,6 +82,10 @@
_printUsage();
return;
}
+ if (configuration.jsonHelp) {
+ stdout.write(jsonEncode(Configuration.jsonSchema));
+ return;
+ }
if (configuration.version) {
var version = testVersion;
diff --git a/pkgs/test_core/lib/src/runner/configuration.dart b/pkgs/test_core/lib/src/runner/configuration.dart
index 8ba4aa8..c6cfab0 100644
--- a/pkgs/test_core/lib/src/runner/configuration.dart
+++ b/pkgs/test_core/lib/src/runner/configuration.dart
@@ -42,10 +42,16 @@
/// The usage string for the command-line arguments.
static String get usage => args.usage;
+ static Map<String, Object?> get jsonSchema => args.jsonSchema;
+
/// Whether `--help` was passed.
bool get help => _help ?? false;
final bool? _help;
+ /// Whether `--json-help` was passed.
+ bool get jsonHelp => _jsonHelp ?? false;
+ final bool? _jsonHelp;
+
/// Custom HTML template file.
final String? customHtmlTemplatePath;
@@ -248,6 +254,7 @@
factory Configuration(
{required bool? help,
+ bool? jsonHelp,
required String? customHtmlTemplatePath,
required bool? version,
required bool? pauseAfterLoad,
@@ -300,6 +307,7 @@
var chosenPresetSet = chosenPresets?.toSet();
var configuration = Configuration._(
help: help,
+ jsonHelp: jsonHelp,
customHtmlTemplatePath: customHtmlTemplatePath,
version: version,
pauseAfterLoad: pauseAfterLoad,
@@ -731,6 +739,7 @@
/// Unlike [Configuration.new], this assumes [presets] is already resolved.
Configuration._(
{required bool? help,
+ required bool? jsonHelp,
required this.customHtmlTemplatePath,
required bool? version,
required bool? pauseAfterLoad,
@@ -759,6 +768,7 @@
required Iterable<Pattern>? globalPatterns,
required SuiteConfiguration? suiteDefaults})
: _help = help,
+ _jsonHelp = jsonHelp,
_version = version,
_pauseAfterLoad = pauseAfterLoad,
_debug = debug,
@@ -814,6 +824,7 @@
suiteDefaults: suiteConfig,
globalPatterns: null,
help: null,
+ jsonHelp: null,
customHtmlTemplatePath: null,
version: null,
pauseAfterLoad: null,
@@ -911,6 +922,7 @@
var result = Configuration._(
help: other._help ?? _help,
+ jsonHelp: other._jsonHelp ?? _jsonHelp,
customHtmlTemplatePath:
other.customHtmlTemplatePath ?? customHtmlTemplatePath,
version: other._version ?? _version,
@@ -1006,6 +1018,7 @@
Iterable<String>? addTags}) {
var config = Configuration._(
help: help ?? _help,
+ jsonHelp: _jsonHelp,
customHtmlTemplatePath:
customHtmlTemplatePath ?? this.customHtmlTemplatePath,
version: version ?? _version,
diff --git a/pkgs/test_core/lib/src/runner/configuration/args.dart b/pkgs/test_core/lib/src/runner/configuration/args.dart
index e981bed..eabf197 100644
--- a/pkgs/test_core/lib/src/runner/configuration/args.dart
+++ b/pkgs/test_core/lib/src/runner/configuration/args.dart
@@ -26,6 +26,7 @@
parser.addFlag('help',
abbr: 'h', negatable: false, help: 'Show this usage information.');
+ parser.addFlag('json-help', negatable: false, hide: true);
parser.addFlag('version',
negatable: false, help: 'Show the package:test version.');
@@ -183,6 +184,8 @@
/// The usage string for the command-line arguments.
String get usage => _parser.usage;
+Map<String, Object?> get jsonSchema => _parser.jsonSchema;
+
/// Parses the configuration from [args].
///
/// Throws a [FormatException] if [args] are invalid.
@@ -316,6 +319,7 @@
return Configuration(
help: _ifParsed('help'),
+ jsonHelp: _ifParsed('json-help'),
version: _ifParsed('version'),
verboseTrace: _ifParsed('verbose-trace'),
chainStackTraces: _ifParsed('chain-stack-traces'),
diff --git a/pkgs/test_core/pubspec.yaml b/pkgs/test_core/pubspec.yaml
index 78cc8ea..c386e69 100644
--- a/pkgs/test_core/pubspec.yaml
+++ b/pkgs/test_core/pubspec.yaml
@@ -34,3 +34,10 @@
dev_dependencies:
test: any
+
+dependency_overrides:
+ args:
+ git:
+ url: https://github.com/dart-lang/core.git
+ path: pkgs/args
+ ref: json-schema