-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathBumpCommand.cs
58 lines (44 loc) · 1.4 KB
/
BumpCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.CommandLine;
using System.Linq;
using System.Threading.Tasks;
using AndroidBinderator;
namespace Xamarin.AndroidBinderator.Tool;
static class BumpCommand
{
public static Command Build ()
{
var update_command = new Command ("bump", "Increments the NuGet patch version of all packages in a config.json file.");
var config_file_option = new Option<string> (["--config-file", "-c", "-config="], "JSON config file") { IsRequired = true };
update_command.Add (config_file_option);
update_command.SetHandler (
RunBumpCommand,
config_file_option
);
return update_command;
}
static async Task RunBumpCommand (string configFile)
{
var config = await BindingConfig.Load (configFile);
foreach (var art in config.MavenArtifacts.Where (a => !a.DependencyOnly)) {
var version = "";
var release = "";
var revision = 0;
var str = art.NugetVersion ?? string.Empty;
if (str.Contains ('-')) {
release = str.Substring (str.IndexOf ('-'));
str = str.Substring (0, str.LastIndexOf ('-'));
}
var period_count = str.Count (c => c == '.');
if (period_count == 2) {
version = str;
revision = 1;
} else if (period_count == 3) {
version = str.Substring (0, str.LastIndexOf ('.'));
revision = int.Parse (str.Substring (str.LastIndexOf ('.') + 1));
revision++;
}
art.NugetVersion = $"{version}.{revision}{release}";
}
config.Save (configFile);
}
}