Skip to content

Commit 3fafccf

Browse files
committed
bugfixes?
1 parent 9715dd9 commit 3fafccf

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

Program.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public static void Main(string[] args)
2828

2929
static async Task Run(string[] args, CancellationToken ct)
3030
{
31-
if (args.Length == 0)
31+
string? action = args.Length > 0 && !args[0].StartsWith('-') ? args[0] : null;
32+
if (action is not null) args = args[1..];
33+
34+
if (action is null && (args.Contains("-h") || args.Contains("--help") || args.Length == 0))
3235
{
3336
Help.PrintHelp(null);
3437
return;
@@ -42,16 +45,16 @@ static async Task Run(string[] args, CancellationToken ct)
4245
Actions.Install.PerformInstall();
4346
}
4447

45-
switch (args[0])
48+
switch (action)
4649
{
4750
case "update":
4851
if (args.ContainsAny("--help", "-h"))
4952
{
50-
Help.PrintHelp(args[0]);
53+
Help.PrintHelp(action);
5154
break;
5255
}
5356

54-
if (args.Length != 1)
57+
if (args.Length != 0)
5558
{
5659
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
5760
}
@@ -61,11 +64,11 @@ static async Task Run(string[] args, CancellationToken ct)
6164
case "check":
6265
if (args.ContainsAny("--help", "-h"))
6366
{
64-
Help.PrintHelp(args[0]);
67+
Help.PrintHelp(action);
6568
break;
6669
}
6770

68-
if (args.Length != 1)
71+
if (args.Length != 0)
6972
{
7073
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
7174
}
@@ -75,39 +78,39 @@ static async Task Run(string[] args, CancellationToken ct)
7578
case "add":
7679
if (args.ContainsAny("--help", "-h"))
7780
{
78-
Help.PrintHelp(args[0]);
81+
Help.PrintHelp(action);
7982
break;
8083
}
8184

82-
if (args.Length < 2)
85+
if (args.Length < 1)
8386
{
8487
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
8588
}
8689

87-
await Actions.Add.PerformAdd(args[1..], ct);
90+
await Actions.Add.PerformAdd(args, ct);
8891
break;
8992
case "remove":
9093
if (args.ContainsAny("--help", "-h"))
9194
{
92-
Help.PrintHelp(args[0]);
95+
Help.PrintHelp(action);
9396
break;
9497
}
9598

96-
if (args.Length < 2)
99+
if (args.Length < 1)
97100
{
98101
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
99102
}
100103

101-
await Actions.Remove.PerformRemove(args[1..], ct);
104+
await Actions.Remove.PerformRemove(args, ct);
102105
break;
103106
case "list":
104107
if (args.ContainsAny("--help", "-h"))
105108
{
106-
Help.PrintHelp(args[0]);
109+
Help.PrintHelp(action);
107110
break;
108111
}
109112

110-
if (args.Length != 1)
113+
if (args.Length != 0)
111114
{
112115
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
113116
}
@@ -117,25 +120,19 @@ static async Task Run(string[] args, CancellationToken ct)
117120
case "change":
118121
if (args.ContainsAny("--help", "-h"))
119122
{
120-
Help.PrintHelp(args[0]);
123+
Help.PrintHelp(action);
121124
break;
122125
}
123126

124-
if (args.Length != 2)
127+
if (args.Length != 1)
125128
{
126129
throw new ApplicationArgumentsException($"Wrong number of arguments passed");
127130
}
128131

129-
await Actions.Change.PerformChange(args[1], ct);
132+
await Actions.Change.PerformChange(args[0], ct);
130133
break;
131134
default:
132-
if (args.ContainsAny("--help", "-h"))
133-
{
134-
Help.PrintHelp(null);
135-
break;
136-
}
137-
138-
throw new ApplicationArgumentsException($"Invalid action {args[0]}");
135+
throw new ApplicationArgumentsException($"Invalid action {action}");
139136
}
140137
}
141138
}

Source/Actions/Add.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ public static class Add
44
{
55
public static async Task PerformAdd(string[] queries, CancellationToken ct)
66
{
7+
bool didAddSomething = false;
8+
79
foreach (string query in queries)
810
{
911
if (Context.Instance.Modlist.Mods.Any(v => v.Id == query) &&
@@ -33,8 +35,11 @@ public static async Task PerformAdd(string[] queries, CancellationToken ct)
3335
Id = id,
3436
Name = v.Value.Name,
3537
});
38+
didAddSomething = true;
3639
}
3740

41+
if (!didAddSomething) return;
42+
3843
Changes changes = await ModInstaller.CheckChanges(ct);
3944

4045
await ModInstaller.PerformChanges(changes, ct);

Source/Actions/Update.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ void AddThese(IEnumerable<string> mods)
109109
}
110110
}
111111

112+
if (modUpdates.Count == 0)
113+
{
114+
Log.Info($"All mods are up to date");
115+
}
116+
112117
return new Changes()
113118
{
114119
Install = modUpdates.ToImmutable(),

Source/ModInstaller.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,19 @@ public static async Task PerformChanges(Changes changes, CancellationToken ct)
334334

335335
{
336336
int nameMaxWidth = 0;
337-
nameMaxWidth = changes.Install.Aggregate(nameMaxWidth, (a, v) => Math.Max(a, v.Name.Length));
338-
nameMaxWidth = changes.Uninstall.Aggregate(nameMaxWidth, (a, v) => Math.Max(a, v.Name.Length));
339-
nameMaxWidth += 2;
337+
if (!Console.IsOutputRedirected)
338+
{
339+
nameMaxWidth = changes.Install.Aggregate(nameMaxWidth, (a, v) => Math.Max(a, v.Name.Length));
340+
nameMaxWidth = changes.Uninstall.Aggregate(nameMaxWidth, (a, v) => Math.Max(a, v.Name.Length));
341+
nameMaxWidth += 2;
342+
nameMaxWidth = Math.Clamp(nameMaxWidth, 4, Console.WindowWidth * 2 / 3);
343+
}
340344

341345
if (!changes.IsEmpty)
342346
{
343347
Console.WriteLine();
344348
}
345349

346-
nameMaxWidth = Math.Clamp(nameMaxWidth, 4, Console.WindowWidth * 2 / 3);
347-
348350
foreach (ModInstallInfo update in changes.Install)
349351
{
350352
string name = update.Name;
@@ -367,16 +369,24 @@ public static async Task PerformChanges(Changes changes, CancellationToken ct)
367369
}
368370
Console.ResetColor();
369371

370-
if (name.Length > nameMaxWidth)
372+
if (Console.IsOutputRedirected)
371373
{
372-
Console.Write(name.AsSpan(0, nameMaxWidth - 3));
373-
Console.Write("...");
374+
Console.Write(name);
375+
Console.Write(' ');
374376
}
375377
else
376378
{
377-
Console.Write(name);
379+
if (name.Length > nameMaxWidth)
380+
{
381+
Console.Write(name.AsSpan(0, nameMaxWidth - 3));
382+
Console.Write("...");
383+
}
384+
else
385+
{
386+
Console.Write(name);
387+
}
388+
Console.Write(new string(' ', nameMaxWidth - name.Length));
378389
}
379-
Console.Write(new string(' ', nameMaxWidth - name.Length));
380390

381391
IMod? existing = update.LockEntry is null ? null : mods.FirstOrDefault(v => Path.GetFileName(v.FileName) == update.LockEntry.FileName).Mod;
382392

publish.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22
dotnet publish ./mmm.csproj -c Release -o ./publish/linux-x64 -r linux-x64 /p:UseAppHost=true
33
dotnet publish ./mmm.csproj -c Release -o ./publish/win-x64 -r win-x64 /p:UseAppHost=true
4-
mv ./publish/linux-x64/mmm ./publish/linux-x64/mmm-linux-x64
5-
mv ./publish/win-x64/mmm.exe ./publish/win-x64/mmm-win-x64.exe
4+
5+
mv ./publish/linux-x64/mmm ./publish/mmm-linux-x64
6+
rm -r ./publish/linux-x64
7+
8+
mv ./publish/win-x64/mmm.exe ./publish/mmm-win-x64.exe
9+
rm -r ./publish/win-x64

0 commit comments

Comments
 (0)