-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add!: proper sub commands for bump and log commands (#70)
- Loading branch information
1 parent
ac25b19
commit e1e59c7
Showing
8 changed files
with
152 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,41 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:cider/src/project.dart'; | ||
import 'package:cider/src/cli/command/bump_sub_command.dart'; | ||
import 'package:cider/src/cli/command/cider_command.dart'; | ||
import 'package:version_manipulation/mutations.dart'; | ||
|
||
enum BumpType { | ||
breaking(BumpBreaking(), 'Bump the breaking version'), | ||
major(BumpMajor(), 'Bump the major version'), | ||
minor(BumpMinor(), 'Bump the minor version'), | ||
patch(BumpPatch(), 'Bump the patch version'), | ||
build(BumpBuild(), 'Bump the build version'), | ||
pre(BumpPreRelease(), 'Bump the pre-release version'), | ||
release(Release(), 'Bump the release version'); | ||
|
||
const BumpType(this.mutation, this.description); | ||
|
||
final VersionMutation mutation; | ||
final String description; | ||
} | ||
|
||
class BumpCommand extends CiderCommand { | ||
BumpCommand(super.printer) { | ||
mutations.keys.forEach(argParser.addCommand); | ||
argParser | ||
..addFlag('keep-build', help: 'Keep the existing build') | ||
..addFlag('bump-build', help: 'Also bump the build') | ||
..addOption('build', | ||
help: 'Sets the build to the given value', defaultsTo: '') | ||
..addOption('pre', | ||
help: 'Sets the pre-release to the given value', defaultsTo: ''); | ||
for (final type in BumpType.values) { | ||
addSubcommand( | ||
BumpSubCommand(type.name, type.description, type.mutation, printer), | ||
); | ||
} | ||
} | ||
|
||
static const mutations = <String, VersionMutation>{ | ||
'breaking': BumpBreaking(), | ||
'build': BumpBuild(), | ||
'major': BumpMajor(), | ||
'minor': BumpMinor(), | ||
'patch': BumpPatch(), | ||
'pre': BumpPreRelease(), | ||
'release': Release(), | ||
}; | ||
|
||
@override | ||
final name = 'bump'; | ||
@override | ||
final description = 'Bump project version'; | ||
|
||
@override | ||
Future<int> exec(Project project) async { | ||
final part = argResults!.command?.name ?? | ||
(throw ArgumentError('Version part must be specified')); | ||
final result = await project.bumpVersion(mutations[part]!, | ||
keepBuild: argResults!['keep-build'], | ||
bumpBuild: argResults!['bump-build'], | ||
build: argResults!['build'], | ||
pre: argResults!['pre']); | ||
printer.out.writeln(result); | ||
return 0; | ||
throw UsageException( | ||
'Bump command can only be used with subcommands', usage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:cider/src/cli/console.dart'; | ||
import 'package:cider/src/project.dart'; | ||
import 'package:cider/src/cli/command/cider_command.dart'; | ||
import 'package:version_manipulation/mutations.dart'; | ||
|
||
class BumpSubCommand extends CiderCommand { | ||
BumpSubCommand(this.name, this.description, this.mutation, Console printer) | ||
: super(printer) { | ||
argParser | ||
..addFlag('keep-build', help: 'Keep the existing build') | ||
..addFlag('bump-build', help: 'Also bump the build') | ||
..addOption('build', | ||
help: 'Sets the build to the given value', defaultsTo: '') | ||
..addOption('pre', | ||
help: 'Sets the pre-release to the given value', defaultsTo: ''); | ||
} | ||
|
||
@override | ||
final String name; | ||
|
||
@override | ||
final String description; | ||
|
||
final VersionMutation mutation; | ||
|
||
@override | ||
Future<int> exec(Project project) async { | ||
final result = await project.bumpVersion(mutation, | ||
keepBuild: argResults!['keep-build'], | ||
bumpBuild: argResults!['bump-build'], | ||
build: argResults!['build'], | ||
pre: argResults!['pre']); | ||
printer.out.writeln(result); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:cider/src/cli/command/log_command.dart'; | ||
import 'package:cider/src/cli/console.dart'; | ||
import 'package:cider/src/project.dart'; | ||
import 'package:cider/src/cli/command/cider_command.dart'; | ||
|
||
class LogSubCommand extends CiderCommand { | ||
LogSubCommand(this.name, this.description, this.type, Console printer) | ||
: super(printer); | ||
|
||
@override | ||
final String name; | ||
|
||
@override | ||
final String description; | ||
|
||
final LogType type; | ||
|
||
@override | ||
Future<int> exec(Project project) async { | ||
await project.addUnreleased(type.name, argResults!.rest.first); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:test/test.dart'; | ||
|
||
void expectSubcommandsUsage(String output, {String? command}) { | ||
if (command != null) { | ||
expect(output, contains('Usage: cider $command <subcommand> [arguments]')); | ||
} | ||
expect(output, contains('-h, --help Print this usage information.')); | ||
expect(output, contains('Available subcommands:')); | ||
expect(output, contains('Run "cider help" to see global options.')); | ||
} |