mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Move the pack weight converter's command line out of production code
Core production code may not write to the process streams; the entry point now lives in the test sources.
This commit is contained in:
1 parent
1e44f45a34
commit
1dea1b098d
2 files changed
+63
-30
No files matched your search
@@ -55,7 +55,7 @@ import java.util.stream.Stream;
|
||||
* a weight above {@link Weighted#MAX_WEIGHT} stops the conversion. A pack with lists already converted and lists not yet
|
||||
* converted cannot be told apart from rarity 1 and is refused.
|
||||
* <p>
|
||||
* Usage: {@code PackWeightConverter [--dry-run] <pack folder>...}
|
||||
* {@code PackWeightConverterCli} in the test sources runs it from the command line.
|
||||
*/
|
||||
public final class PackWeightConverter {
|
||||
private static final String INDENT_STEP = " ";
|
||||
@@ -118,35 +118,6 @@ public final class PackWeightConverter {
|
||||
return new Result(changed, List.copyOf(converter.warnings));
|
||||
}
|
||||
|
||||
public static void main(String[] arguments) throws IOException {
|
||||
boolean dryRun = false;
|
||||
List<Path> packs = new ArrayList<>();
|
||||
for (String argument : arguments) {
|
||||
if (argument.equals("--dry-run")) {
|
||||
dryRun = true;
|
||||
} else {
|
||||
packs.add(Path.of(argument));
|
||||
}
|
||||
}
|
||||
|
||||
if (packs.isEmpty()) {
|
||||
System.err.println("Usage: PackWeightConverter [--dry-run] <pack folder>...");
|
||||
System.exit(2);
|
||||
}
|
||||
|
||||
for (Path folder : packs) {
|
||||
try {
|
||||
Result result = convert(folder, dryRun);
|
||||
result.changedFiles().forEach(System.out::println);
|
||||
result.warnings().forEach(warning -> System.out.println("warning: " + warning));
|
||||
System.out.println(folder + ": " + result.changedFiles().size() + " files " + (dryRun ? "would change" : "changed"));
|
||||
} catch (ConversionException refusal) {
|
||||
System.err.println(folder + ": " + refusal.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The converted text of the file; null when nothing in it changes. */
|
||||
private String convertFile(String folder, Path file) throws IOException {
|
||||
currentFile = relative(pack, file);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.pack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Usage: {@code PackWeightConverterCli [--dry-run] <pack folder>...} */
|
||||
public final class PackWeightConverterCli {
|
||||
private static final int EXIT_USAGE = 2;
|
||||
private static final int EXIT_REFUSED = 1;
|
||||
|
||||
private PackWeightConverterCli() {
|
||||
}
|
||||
|
||||
public static void main(String[] arguments) throws IOException {
|
||||
boolean dryRun = false;
|
||||
List<Path> packs = new ArrayList<>();
|
||||
for (String argument : arguments) {
|
||||
if (argument.equals("--dry-run")) {
|
||||
dryRun = true;
|
||||
} else {
|
||||
packs.add(Path.of(argument));
|
||||
}
|
||||
}
|
||||
|
||||
if (packs.isEmpty()) {
|
||||
System.err.println("Usage: PackWeightConverterCli [--dry-run] <pack folder>...");
|
||||
System.exit(EXIT_USAGE);
|
||||
}
|
||||
|
||||
for (Path folder : packs) {
|
||||
try {
|
||||
PackWeightConverter.Result result = PackWeightConverter.convert(folder, dryRun);
|
||||
result.changedFiles().forEach(System.out::println);
|
||||
result.warnings().forEach(warning -> System.out.println("warning: " + warning));
|
||||
System.out.println(folder + ": " + result.changedFiles().size() + " files " + (dryRun ? "would change" : "changed"));
|
||||
} catch (PackWeightConverter.ConversionException refusal) {
|
||||
System.err.println(folder + ": " + refusal.getMessage());
|
||||
System.exit(EXIT_REFUSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user