refactor(profile): read the parse's profile snapshot in restart and config show (#34)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-08 22:25:23 -05:00
1 parent 5c0cc339bf
commit bc59dff8c3
7 files changed
+90 -95

No files matched your search

@@ -32,15 +32,30 @@ public class ProfileDefaultValueProvider implements IDefaultValueProvider {
private String resolvedName;
private Profile resolved;
public ProfileDefaultValueProvider() {
this(new ProfileStore());
}
/** Test seam: a store pointed at a temporary profiles directory. */
public ProfileDefaultValueProvider(ProfileStore store) {
this.store = store;
}
/**
* The provider {@code FlociCli.buildCommandLine} registered, as picocli propagated it to
* {@code spec}'s command. A command that reads a profile back after parsing goes through here,
* so it reuses the store the CLI was built with and the snapshot the parse already took, never a
* second read of the file. A command built by hand, outside that wiring, gets a fresh provider
* over the default store.
*/
public static ProfileDefaultValueProvider of(CommandSpec spec) {
if (spec != null && spec.commandLine() != null
&& spec.commandLine().getDefaultValueProvider() instanceof ProfileDefaultValueProvider provider) {
return provider;
}
return new ProfileDefaultValueProvider(new ProfileStore());
}
/** The store profiles are read from. */
public ProfileStore store() {
return store;
}
/**
* The profile this provider resolved during the last parse, if any. Reading it costs nothing
* and, crucially, costs no second read of the file: a caller that needs both which keys the