Skip to content

Commit

Permalink
chore: Bumped sdk versions down to 3.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
pattobrien committed Feb 13, 2024
1 parent 8a0dacf commit 5d88fea
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 114 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 1.0.0
publish_to: none

environment:
sdk: ^3.2.0
sdk: ^3.0.0

dependencies:
args: ^2.4.2
Expand Down
180 changes: 90 additions & 90 deletions lib/runner.dart
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:json_annotation/json_annotation.dart';
// import 'package:args/args.dart';
// import 'package:args/command_runner.dart';
// import 'package:json_annotation/json_annotation.dart';

part 'runner.g.dart';
// part 'runner.g.dart';

void main() async {
final runner = ExampleRunner();
final args = ['example', '--foo', 'bar']; // explicit option supplied
await runner.run(args);
// void main() async {
// final runner = ExampleRunner();
// final args = ['example', '--foo', 'bar']; // explicit option supplied
// await runner.run(args);

final args2 = ['example']; // no explicit option supplied
await runner.run(args2);
}
// final args2 = ['example']; // no explicit option supplied
// await runner.run(args2);
// }

class ExampleRunner extends CommandRunner {
ExampleRunner() : super('example', 'Example command runner.') {
addCommand(ExampleCommand());
}
}
// class ExampleRunner extends CommandRunner {
// ExampleRunner() : super('example', 'Example command runner.') {
// addCommand(ExampleCommand());
// }
// }

class ExampleCommand extends Command {
@override
String get description => 'Example command description.';
// class ExampleCommand extends Command {
// @override
// String get description => 'Example command description.';

@override
String get name => 'example';
// @override
// String get name => 'example';

@override
ArgParser get argParser => ArgParser()
..addOption(
'foo',
abbr: 'f',
mandatory: false,
defaultsTo: 'default',
)
..addMultiOption(
'bar',
abbr: 'b',
splitCommas: true,
)
..addFlag(
'bar',
abbr: 'b',
negatable: false,
);
// @override
// ArgParser get argParser => ArgParser()
// ..addOption(
// 'foo',
// abbr: 'f',
// mandatory: false,
// defaultsTo: 'default',
// )
// ..addMultiOption(
// 'bar',
// abbr: 'b',
// splitCommas: true,
// )
// ..addFlag(
// 'bar',
// abbr: 'b',
// negatable: false,
// );

@override
run() {
final results = argResults!;
// @override
// run() {
// final results = argResults!;

userFunction(
results['bar'] as List<String>,
foo: results['foo'] as String,
baz: results['baz'] != null ? int.parse(results['baz']) : null,
email: results.wasParsed(
'email') // conditional to check if option was supplied (only necessary for `canBeNull` parameters)
? Email.parse(results['email']) // the `parse` method
: const Email('default'), // copied from `defaultValueCode`
);
}
}
// userFunction(
// results['bar'] as List<String>,
// foo: results['foo'] as String,
// baz: results['baz'] != null ? int.parse(results['baz']) : null,
// email: results.wasParsed(
// 'email') // conditional to check if option was supplied (only necessary for `canBeNull` parameters)
// ? Email.parse(results['email']) // the `parse` method
// : const Email('default'), // copied from `defaultValueCode`
// );
// }
// }

void userFunction(
List<String> bar, {
required String foo,
int? baz = 42,
Email email = const Email('default'),
}) {
throw UnimplementedError();
}
// void userFunction(
// List<String> bar, {
// required String foo,
// int? baz = 42,
// Email email = const Email('default'),
// }) {
// throw UnimplementedError();
// }

extension type const Email(String value) {
factory Email.parse(String value) {
// check if value is valid
final regexp = RegExp(r'^\S+@\S+\.\S+$');
if (!regexp.hasMatch(value)) {
throw ArgumentError('Invalid email address');
}
return Email(value);
}
}
// extension type const Email(String value) {
// factory Email.parse(String value) {
// // check if value is valid
// final regexp = RegExp(r'^\S+@\S+\.\S+$');
// if (!regexp.hasMatch(value)) {
// throw ArgumentError('Invalid email address');
// }
// return Email(value);
// }
// }

@JsonSerializable()
class Foo {
final String stringValue;
final bool boolValue;
final int intValue;
final Bar bar;
// @JsonSerializable()
// class Foo {
// final String stringValue;
// final bool boolValue;
// final int intValue;
// final Bar bar;

const Foo({
this.stringValue = 'default',
this.boolValue = true,
this.intValue = 42,
this.bar = const Bar('default'),
});
// const Foo({
// this.stringValue = 'default',
// this.boolValue = true,
// this.intValue = 42,
// this.bar = const Bar('default'),
// });

factory Foo.fromJson(Map<String, dynamic> json) => _$FooFromJson(json);
}
// factory Foo.fromJson(Map<String, dynamic> json) => _$FooFromJson(json);
// }

extension type const Bar(String val) {
factory Bar.fromJson(Map<String, dynamic> json) {
return Bar(json['val'] as String);
}
}
// extension type const Bar(String val) {
// factory Bar.fromJson(Map<String, dynamic> json) {
// return Bar(json['val'] as String);
// }
// }
30 changes: 15 additions & 15 deletions lib/runner.g.dart

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

2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.3.0 <4.0.0"
dart: ">=3.2.0 <4.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: cli_gen
description: The workspace for the cli_gen package.

environment:
sdk: ^3.3.0
sdk: ^3.0.0

dependencies:
analyzer: ^6.4.1
Expand Down
11 changes: 10 additions & 1 deletion src/cli_annotations/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
name: cli_annotations
description: A sample command-line application.
version: 0.1.0-dev.1
homepage: https://github.com/pattobrien/cli-gen
repository: https://github.com/pattobrien/cli-gen
issue_tracker: https://github.com/pattobrien/cli-gen/issues

topics:
- cli
- args
- codegen
- macros

environment:
sdk: ^3.2.0
sdk: ^3.0.0

dependencies:
args: ^2.4.2
Expand Down
5 changes: 2 additions & 3 deletions src/cli_gen/lib/src/code/models/command_parameter_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ class CommandParameterModel {
Expression? get computedDefaultValue {
return annotations.map((e) => e.defaultsTo).firstOrNull ??
(_computedDefaultValue != null
// ? CodeExpression(Code("'$_computedDefaultValue'"))
? type.symbol == 'bool'
? literalBool(bool.parse(_computedDefaultValue))
: literalString(_computedDefaultValue)
? literalBool(bool.parse(_computedDefaultValue!))
: literalString(_computedDefaultValue!)
: null);
}

Expand Down
11 changes: 10 additions & 1 deletion src/cli_gen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ name: cli_gen
description: A sample command-line application.
version: 0.1.0-dev.1
publish_to: none
homepage: https://github.com/pattobrien/cli-gen
repository: https://github.com/pattobrien/cli-gen
issue_tracker: https://github.com/pattobrien/cli-gen/issues

topics:
- cli
- args
- codegen
- macros

environment:
sdk: ^3.2.0
sdk: ^3.0.0

dependencies:
analyzer: ^6.4.1
Expand Down
2 changes: 1 addition & 1 deletion src/cli_gen/test/example_project/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 1.0.0
publish_to: none

environment:
sdk: ^3.2.0
sdk: ^3.0.0

dependencies:
cli_annotations:
Expand Down

0 comments on commit 5d88fea

Please sign in to comment.