Skip to content
Merged
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
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ jobs:
- isolated_object
- serverpod_logging
- serverpod_logging_cli
platform: [ubuntu-latest]
platform: [ubuntu-latest, windows-latest]
include:
- package: cli_tools
platform: windows-latest
dart: 3.9
- package: cli_tools
platform: macos-latest
dart: 3.9
Expand Down
1 change: 1 addition & 0 deletions packages/cli_tools/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ analyzer:
linter:
rules:
prefer_relative_imports: true
avoid_final_parameters: false
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ abstract class BetterCommand<O extends OptionDefinition, T> extends Command<T> {
Configuration<O> resolveConfiguration(final ArgResults? argResults) {
return Configuration.resolveNoExcept(
options: options,
// ignore: deprecated_member_use
argResults: argResults,
env: envVariables,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class BetterCommandRunner<O extends OptionDefinition, T>
Configuration<O> resolveConfiguration(final ArgResults? argResults) {
return Configuration.resolveNoExcept(
options: _globalOptions,
// ignore: deprecated_member_use
argResults: argResults,
env: envVariables,
ignoreUnexpectedPositionalArgs: true,
Expand Down
1 change: 1 addition & 0 deletions packages/config/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ analyzer:
linter:
rules:
prefer_relative_imports: true
avoid_final_parameters: false
14 changes: 10 additions & 4 deletions packages/config/lib/src/args_compatibility/config_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:io' show Platform;

import 'package:args/args.dart';

import '../config/arg_parser_bridge.dart';
import '../config/arg_parser_facade.dart';
import '../config/configuration.dart';
import '../config/configuration_broker.dart';
import '../config/option_types.dart';
Expand Down Expand Up @@ -246,11 +248,15 @@ class ConfigParser implements ArgParser {
}) {
validateOptions(_optionDefinitions);

final argResults = parser.parse(args);
final parsedArgs = legacyParsedArgs(
_optionDefinitions,
args,
allowTrailingOptions: allowTrailingOptions,
);

final configuration = Configuration.resolve(
options: _optionDefinitions,
argResults: argResults,
parsedArgs: parsedArgs,
env: env ?? Platform.environment,
configBroker: configBroker,
presetValues: presetValues,
Expand All @@ -261,8 +267,8 @@ class ConfigParser implements ArgParser {

return ConfigResults(
configuration,
argResults.arguments,
argResults.rest,
parsedArgs.argResults.arguments,
parsedArgs.argResults.rest,
);
}

Expand Down
11 changes: 11 additions & 0 deletions packages/config/lib/src/config/arg_parser/arg_parser.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// Command line scanning and parsing.
library;

export 'command_definition.dart';
export 'parser.dart'
show
ArgParseResult,
scanAndParseArgs,
scanAndParseCommands,
unknownSubcommandErrorPrefix;
export 'scanner.dart' show DoubleDashHandling, ScanMode, optionAwaitingValue;
95 changes: 95 additions & 0 deletions packages/config/lib/src/config/arg_parser/command_definition.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import '../options.dart' show OptionDefinition;

abstract interface class CommandDefinition<O extends OptionDefinition> {
/// The name of this command.
String get name;

/// Generates a formatted string with usage information for this command.
String get usage;

/// Describes usage documentation and visibility for this command.
CommandUsageDefinition get usageDefinition;

/// Describes alternate names resolution for this command.
CommandAliasesDefinition get aliasesDefinition;

/// Persistent options - the options of the current command that continue to
/// be available for all subcommands.
/// On the root command, this is the global options.
List<O> get persistentOptions;

/// Regular options - the options of the current command that are not
/// persistent.
List<O> get options;

/// All the defined options of this command, depending on the passed flag.
List<OptionDefinition> allOptions({final bool onlyPersistent = false});

List<CommandDefinition> get subcommands;

/// Whether this command can be run as the last command on the command line
/// even if it has subcommands registered. Default is false.
/// If false and this command is the last command found on the command line,
/// the command line parser will yield an error.
bool get canRunAsLeafCommand => false;
}

class CommandUsageDefinition {
// TODO: Support overriding `summary` and `invocation` of the formatted usage
// like the old Command did.

/// A description of this command, included in usage.
final String description;

/// An optional footer which is added to the end of the usage.
final String? usageFooter;

/// The command's category.
///
/// Displayed in [parent]'s [CommandRunner.usage]. Commands with categories
/// will be grouped together, and displayed after commands without a category.
final String? category;

/// Whether or not this command should be hidden from help listings.
///
/// By default, leaf commands are always visible. Branch commands are visible
/// as long as any of their leaf commands are visible.
final bool hidden;

const CommandUsageDefinition({
final String? description,
this.usageFooter,
this.category,
final bool? hidden,
}) : description = description ?? '',
hidden = hidden ?? false;
}

class CommandAliasesDefinition {
/// Alternate names for this command.
final List<String> aliases;

/// Alternate non-functional names for this command.
///
/// These names won't be used in the documentation, and also they won't work
/// when invoked on the command line. But if an unknown command is used it
/// will be matched against this when creating suggestions.
///
/// A name does not have to be repeated both here and in [aliases].
final List<String> suggestionAliases;

/// The maximum edit distance allowed when suggesting possible intended
/// commands.
///
/// Set to `0` in order to disable suggestions, defaults to `2`.
// TODO: Make this global on the CommandRunner instead?
final int suggestionDistanceLimit;

const CommandAliasesDefinition({
final List<String>? aliases,
final List<String>? suggestionAliases,
final int? suggestionDistanceLimit,
}) : aliases = aliases ?? const <String>[],
suggestionAliases = suggestionAliases ?? const <String>[],
suggestionDistanceLimit = suggestionDistanceLimit ?? 2;
}
Loading
Loading