Skip to content

Commit 46e35e4

Browse files
committed
Add CLI help option
1 parent 91899fc commit 46e35e4

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "maven" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"
12+
ignore:
13+
# Ignore all minor and patch updates.
14+
- dependency-name: "*"
15+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ Fedora 42 systems, using the [KDE Edition](https://fedoraproject.org/kde),
55
which comes with Java 21 preinstalled, as a starting point.
66
It also sets some configuration options useful for development work and system administration.
77

8+
Current actions that can be applied (each needs to be confirmed first):
9+
10+
1. Install RPMFusion repositories.
11+
Adds free and nonfree RPMFusion repos and imports their GPG keys.
12+
13+
2. Install additional packages with DNF.
14+
Installs extra packages listed in dnf-install.cf, with the
15+
option to skip selected packages interactively.
16+
17+
3. Remove unnecessary packages.
18+
Removes unwanted packages from dnf-remove.cf and performs autoremove.
19+
20+
4. Install Flatpak applications.
21+
Adds the Flathub remote and installs Flatpaks from flatpak-install.cf.
22+
23+
5. Ensure groups exist and add user.
24+
Creates and assigns admin-related groups such as _docker_, _libvirt_, and _vboxusers_.
25+
26+
6. Enable and start Cockpit.
27+
Enables and starts the systemd service of the Cockpit web-based management interface.
28+
829
### Run commands
930

1031
- App
@@ -13,6 +34,8 @@ It also sets some configuration options useful for development work and system a
1334
java src/main/java/cf/maybelambda/fedora/PostInstallUpdater.java
1435
```
1536

37+
`--help` can be passed to see available options.
38+
1639
- Tests
1740

1841
```

src/main/java/cf/maybelambda/fedora/PostInstallUpdater.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,38 @@ public class PostInstallUpdater {
2323
"https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-42.noarch.rpm",
2424
"https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-42.noarch.rpm"
2525
);
26+
2627
private static final String flatpakRemoteName = "flathub";
2728
private static final String flatpakRemoteUrl = "https://dl.flathub.org/repo/flathub.flatpakrepo";
29+
2830
private static final List<String> groupList = List.of(
2931
"docker", "libvirt", "vboxsf", "vboxusers"
3032
);
33+
34+
private static final String CONFIG_DIR = "src/main/resources";
3135
private static final String DNF_INSTALL_FILE = "dnf-install.cf";
3236
private static final String DNF_REMOVE_FILE = "dnf-remove.cf";
3337
private static final String FLATPAK_INSTALL_FILE = "flatpak-install.cf";
38+
private static final String HELP_FILE = "help.txt";
3439

3540
private static final String RESET = "\u001B[0m";
3641
private static final String YELLOW = "\u001B[33m";
3742

3843
private static boolean dryRun = false;
3944

4045
public static void main(String[] args) {
41-
setDryRun(Arrays.asList(args).contains("--dry-run"));
46+
if (Arrays.asList(args).contains("-h") || Arrays.asList(args).contains("--help")) {
47+
printHelp();
48+
return;
49+
}
50+
4251
List<String> dnfInstallPackages = loadPackageNamesFrom(DNF_INSTALL_FILE);
4352
List<String> dnfRemovePackages = loadPackageNamesFrom(DNF_REMOVE_FILE);
4453
List<String> flatpakInstallPackages = loadPackageNamesFrom(FLATPAK_INSTALL_FILE);
4554
Scanner scanner = new Scanner(System.in);
4655

4756
System.out.println("Fedora Post Install Actions\n");
57+
setDryRun(Arrays.asList(args).contains("--dry-run"));
4858
if (isDryRun()) {
4959
System.out.println("---[Dry Run Mode] Shell Commands will not be executed.---\n");
5060
}
@@ -181,7 +191,7 @@ static int runCommand(String[] command) {
181191
static List<String> loadPackageNamesFrom(String filename) {
182192
List<String> packages = new ArrayList<>();
183193
try {
184-
List<String> lines = Files.readAllLines(Path.of("src/main/resources", filename), StandardCharsets.UTF_8);
194+
List<String> lines = Files.readAllLines(Path.of(CONFIG_DIR, filename), StandardCharsets.UTF_8);
185195
for (String line : lines) {
186196
String trimmed = line.trim();
187197
if (!trimmed.isEmpty() && !trimmed.startsWith("#")) {
@@ -222,4 +232,13 @@ static List<String> promptForExclusions(List<String> packages, Scanner scanner)
222232

223233
return filtered;
224234
}
235+
236+
static void printHelp() {
237+
try {
238+
List<String> lines = Files.readAllLines(Path.of(CONFIG_DIR, HELP_FILE), StandardCharsets.UTF_8);
239+
System.out.println(String.join(System.lineSeparator(), lines));
240+
} catch (IOException e) {
241+
System.err.println("Error reading help file: " + e.getMessage());
242+
}
243+
}
225244
}

src/main/resources/help.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Fedora Post Install Actions
2+
===========================
3+
4+
Usage:
5+
java PostInstallUpdater.java [options]
6+
7+
Options:
8+
-h, --help Show this help page and exit.
9+
--dry-run Print all commands without executing them.
10+
11+
Example:
12+
java PostInstallUpdater.java --dry-run
13+
Goes through all steps without executing system commands.

src/test/java/cf/maybelambda/fedora/PostInstallUpdaterTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,17 @@ void runCommandSkipsExecutionInDryRunMode() {
165165
PostInstallUpdater.setDryRun(false);
166166
}
167167
}
168+
169+
@Test
170+
void helpOptionDisplaysHelpTextAndExits() {
171+
try (MockedStatic<Files> filesMock = mockStatic(Files.class, CALLS_REAL_METHODS)) {
172+
filesMock.when(() -> Files.readAllLines(any(Path.class), eq(StandardCharsets.UTF_8)))
173+
.thenReturn(List.of("Usage instructions go here"));
174+
175+
PostInstallUpdater.main(new String[]{"--help"});
176+
PostInstallUpdater.main(new String[]{"-h"});
177+
178+
filesMock.verify(() -> Files.readAllLines(any(Path.class), eq(StandardCharsets.UTF_8)), Mockito.times(2));
179+
}
180+
}
168181
}

0 commit comments

Comments
 (0)