@@ -28,7 +28,7 @@ protected function configure(): void
2828 $ this ->setDescription ('Increment a version ' );
2929 $ this ->setAliases (['incr ' ]);
3030 $ this ->addArgument ('version ' , InputArgument::REQUIRED , 'Version to increment ' );
31- $ this ->addOption ('part ' , 'p ' , InputArgument::OPTIONAL , 'Part to increment (major, minor, patch) ' , 'patch ' );
31+ $ this ->addOption ('part ' , 'p ' , InputArgument::OPTIONAL , 'Part to increment (major, minor, patch, and prerelease ) ' , 'patch ' );
3232 $ this ->addOption ('build ' , 'b ' , InputArgument::OPTIONAL , 'Build metadata to append to the version ' );
3333 $ this ->addOption ('pre ' , null , InputArgument::OPTIONAL , 'Pre-release identifier to append to the version ' );
3434 $ this ->setHelp (<<<'HELP'
@@ -104,11 +104,29 @@ private function increment(Version $version, string $part, $pre = null, $build =
104104 $ version = $ version ->incrementPatch ();
105105 break ;
106106
107+ case 'prerelease ' :
108+ $ currentPrerelease = $ version ->getPreRelease ();
109+
110+ if ($ currentPrerelease === null ) {
111+ throw new InvalidArgumentException ('Unable to increment prerelease on a version without a prerelease tag. ' );
112+ }
113+
114+ if ($ pre !== null && is_string ($ pre ) && $ pre !== '' ) {
115+ throw new InvalidArgumentException ('Specifying a prerelease tag when incrementing the prerelease part is not allowed. ' );
116+ }
117+
118+ $ identifier = $ currentPrerelease ->getIdentifiers ();
119+ $ preTag = $ identifier [0 ];
120+ $ preVersion = (int ) ($ identifier [1 ] ?? 0 ) + 1 ;
121+ $ version = $ version ->withPreRelease (sprintf ('%s.%d ' , $ preTag , $ preVersion ));
122+
123+ break ;
124+
107125 default :
108- throw new InvalidArgumentException (sprintf ("Invalid part '%s' provided. Expected 'major', 'minor', or 'patch '. " , $ part ));
126+ throw new InvalidArgumentException (sprintf ("Invalid part '%s' provided. Expected 'major', 'minor', 'patch', or 'prerelease '. " , $ part ));
109127 }
110128
111- if (is_string ($ pre ) && $ pre !== '' ) {
129+ if ($ part !== ' prerelease ' && is_string ($ pre ) && $ pre !== '' ) {
112130 $ version = $ version ->withPreRelease ($ pre );
113131 }
114132
0 commit comments