Skip to content

Commit af35055

Browse files
committed
minro fixes, prmopt changes, bump version
1 parent 64e16b8 commit af35055

File tree

15 files changed

+398
-79
lines changed

15 files changed

+398
-79
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ You can also download a specific version, or the latest prerelease version, usin
8484

8585
```bash
8686
# Upgrade (or downgrade!) to a specific version
87-
astra upgrade --version 1.0.0-rc.5
87+
astra upgrade --version 1.0.0-rc.6
8888

8989
# Upgrade to the latest prerelease version
9090
astra upgrade --pre

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ plugins {
1616
}
1717

1818
group = "com.dtsx.astra.cli"
19-
version = "1.0.0-rc.5"
19+
version = "1.0.0-rc.6"
2020

2121
val mockitoAgent = configurations.create("mockitoAgent")
2222

scripts/install.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function Get-Env {
114114
}
115115

116116
# Constants
117-
$ASTRA_CLI_VERSION = "1.0.0-rc.5"
117+
$ASTRA_CLI_VERSION = "1.0.0-rc.6"
118118

119119
if ($env:ASTRA_HOME) {
120120
$ASTRA_CLI_DIR = "$env:ASTRA_HOME\cli"

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ renderCommand() {
3737
}
3838

3939
# Constants
40-
ASTRA_CLI_VERSION="1.0.0-rc.5"
40+
ASTRA_CLI_VERSION="1.0.0-rc.6"
4141

4242
get_astra_dir() {
4343
if [ -n "${ASTRA_HOME:-}" ]; then

src/main/java/com/dtsx/astra/cli/commands/SetupCmd.java

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.List;
2727
import java.util.Optional;
2828
import java.util.function.Supplier;
29+
import java.util.stream.Collectors;
30+
import java.util.stream.Stream;
2931

3032
import static com.dtsx.astra.cli.core.output.ExitCode.INVALID_TOKEN;
3133
import static com.dtsx.astra.cli.core.output.ExitCode.UNSUPPORTED_EXECUTION;
@@ -155,6 +157,14 @@ protected Operation<SetupResult> mkOperation() {
155157
}
156158

157159
private void assertShouldSetup(Path existing) {
160+
assertShouldSetup(existing, true);
161+
}
162+
163+
private void assertShouldContinueIfAlreadySetup(Path existing) {
164+
assertShouldSetup(existing, false);
165+
}
166+
167+
private void assertShouldSetup(Path path, boolean newUser) {
158168
ctx.log().banner();
159169

160170
if (ctx.isNotTty()) {
@@ -170,57 +180,39 @@ private void assertShouldSetup(Path existing) {
170180
}
171181

172182
val prompt = """
173-
@|bold Welcome to the Astra CLI setup!|@
174-
175-
@|faint A configuration file with your profile will be created at|@ @|faint,italic %s|@
183+
@|bold Welcome to the interactive Astra CLI setup!|@
176184
177-
If you'd prefer to provide credentials on a per-command basis rather than storing them in a file, you can either:
178-
- Use the per-command @'!--token!@ flag to pass your existing @!AstraCS!@ token directly.
179-
- Use the per-command @'!--config-file!@ flag to specify an existing @!.astrarc!@ file.
180-
181-
%s
182-
%s
185+
@|faint Your configuration file %s at|@ @|faint,italic %s|@
183186
""".formatted(
184-
existing,
185-
renderComment(ctx.colors(), "Example:"),
186-
renderCommand(ctx.colors(), "${cli.name} db list --token <your_token>")
187+
(newUser) ? "will be created" : "already exists",
188+
path
187189
);
188190

189-
ctx.console().println(trimIndent(prompt));
191+
val addendum = (!newUser)
192+
? NL + NL + "Do you want to continue and create a new profile?"
193+
: mkArgsAddendum();
194+
195+
ctx.console().println(trimIndent(prompt) + addendum);
190196
ctx.console().println();
191197
ctx.console().unsafeReadLine(ctx.colors().format("Press @!Enter!@ to continue, or use @!Ctrl+C!@ to cancel. "), false);
192198
ctx.console().println();
193199
}
194200

195-
private void assertShouldContinueIfAlreadySetup(Path existing) {
196-
ctx.log().banner();
201+
private String mkArgsAddendum() {
202+
if ($env.isEmpty() && $token.isEmpty()) {
203+
if ($name.isPresent()) {
204+
return "%n%n@|faint The profile will be called '%s'.|@".formatted($name.get());
205+
}
206+
return "";
207+
}
197208

198-
val prompt = """
199-
@|bold Looks like you're already set up!|@
200-
201-
@|faint Your config file already exists at|@ @|faint,italic %s|@
202-
203-
Hint: You can use the @'!${cli.name} config!@ commands to manage your profiles.
204-
205-
%s
206-
%s
207-
208-
Do you want to continue and create a new profile?
209-
""".formatted(
210-
existing,
211-
renderComment(ctx.colors(), "Example:"),
212-
renderCommand(ctx.colors(), "${cli.name} config list")
209+
return "%n%n@|faint %s will be created%s.|@".formatted(
210+
$name.map(n -> "Profile '" + n + "'").orElse("The profile"),
211+
Stream.concat(
212+
$token.stream().map(t -> " with token " + t),
213+
$env.stream().map(e -> " in env '" + e.name().toLowerCase() + "'")
214+
).collect(Collectors.joining(""))
213215
);
214-
215-
val shouldContinue = ctx.console().confirm(prompt)
216-
.defaultYes()
217-
.fallbackFlag("")
218-
.fix(List.of(), "")
219-
.clearAfterSelection();
220-
221-
if (!shouldContinue) {
222-
throw new ExecutionCancelledException();
223-
}
224216
}
225217

226218
private void assertShouldOverwriteExistingProfile(Profile existing) {

src/main/java/com/dtsx/astra/cli/commands/UpgradeCmd.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.dtsx.astra.cli.AstraCli;
44
import com.dtsx.astra.cli.core.datatypes.Unit;
5-
import com.dtsx.astra.cli.core.exceptions.internal.cli.ExecutionCancelledException;
65
import com.dtsx.astra.cli.core.help.Example;
76
import com.dtsx.astra.cli.core.models.Version;
87
import com.dtsx.astra.cli.core.output.formats.OutputHuman;
@@ -68,12 +67,6 @@ public static class VersionMod {
6867
public boolean $includePreReleases;
6968
}
7069

71-
@Option(
72-
names = { "-y", "--yes" },
73-
description = "Install the upgrade without any confirmation prompting"
74-
)
75-
public boolean $yes;
76-
7770
@Option(
7871
names = { "--allow-reinstall" },
7972
description = "Allow re-installing the same version"
@@ -115,20 +108,6 @@ protected void confirmUpgrade(Version version, String moveCommand) {
115108
);
116109

117110
ctx.console().println(trimIndent(infoMsg));
118-
119-
if ($yes) {
120-
return;
121-
}
122-
123-
val proceed = ctx.console().confirm(NL + NL + "Do you want to proceed?")
124-
.defaultYes()
125-
.fallbackFlag("--yes")
126-
.fix(originalArgs(), "--yes")
127-
.clearAfterSelection();
128-
129-
if (!proceed) {
130-
throw new ExecutionCancelledException();
131-
}
132111
}
133112

134113
@Override

src/main/java/com/dtsx/astra/cli/core/models/Version.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@EqualsAndHashCode
1616
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
1717
public class Version implements Highlightable, Comparable<Version> {
18-
private static final Pattern VERSION_PATTERN = Pattern.compile("^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:-([a-zA-Z0-9-_]+\\.\\d+))?$");
18+
private static final Pattern VERSION_PATTERN = Pattern.compile("^v?(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-([a-zA-Z0-9-_]+\\.\\d+))?$");
1919

2020
private final int major;
2121
private final int minor;
@@ -29,7 +29,7 @@ public static Either<String, Version> parse(String version) {
2929
if (matcher.matches()) {
3030
val major = Integer.parseInt(matcher.group(1));
3131
val minor = Integer.parseInt(matcher.group(2));
32-
val patch = Integer.parseInt(matcher.group(3));
32+
val patch = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : 0;
3333

3434
val preRelease = Optional.ofNullable(matcher.group(4))
3535
.map((pr) -> {
@@ -39,7 +39,7 @@ public static Either<String, Version> parse(String version) {
3939

4040
return Either.pure(new Version(major, minor, patch, preRelease));
4141
} else {
42-
return Either.left("Invalid version format: " + trimmed + " (expected format: x.y.z[-<label>.n])");
42+
return Either.left("Invalid version format: " + trimmed + " (expected format: x.y[.z][-<label>.n])");
4343
}
4444
});
4545
}

src/main/java/com/dtsx/astra/cli/core/upgrades/UpgradeStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ private static Optional<UpgradeStatus> loadFromExistingPath(Properties propertie
3838
val rawLastChecked = properties.getProperty(LAST_CHECKED_KEY);
3939
val rawLastNotified = properties.getProperty(LAST_NOTIFIED_KEY);
4040

41-
if (rawLatestVersion == null || rawLastChecked == null) {
41+
if (rawLatestVersion == null || rawLastChecked == null || rawLastNotified == null) {
4242
ctx.log().exception("Upgrade notifier properties file is missing required keys. Recreating it.");
4343
return createNewStatusFile(properties, ctx, path);
4444
}
4545

4646
val version = Optional.of(rawLatestVersion).filter(s -> !s.isEmpty()).map(Version::parse);
4747
val lastChecked = Either.tryCatch(() -> Long.parseLong(rawLastChecked), Exception::getMessage);
48-
val lastNotified = Either.tryCatch(() -> Long.parseLong(rawLastNotified), Exception::getMessage);
48+
val lastNotified = Either.tryCatch(() -> Long.parseLong(rawLastNotified), Exception::getMessage);
4949

5050
if (version.isPresent() && version.get().isLeft()) {
5151
ctx.log().exception("Upgrade notifier properties file has invalid latest version value '" + rawLatestVersion + "'. Recreating it.");

src/main/java/com/dtsx/astra/cli/core/upgrades/UpgradeStatusKeeper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static String runUnix(CliContext ctx, UpgradeStatus status, Path path, b
9494
# update properties file
9595
echo "LATEST_VERSION=$latest_version
9696
LAST_CHECKED=$last_checked
97-
LAST_NOTIFIED=$last_notified" > "$(printf %%q '%s')"
97+
LAST_NOTIFIED=$last_notified" > '%s'
9898
""").formatted(pathStr);
9999

100100
return script;

src/main/java/com/dtsx/astra/cli/gateways/upgrade/UpgradeGatewayImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ private Version fetchLatestFullRelease() {
4848

4949
val json = JsonUtils.readTree(response.body());
5050

51+
System.out.println(json.get("tag_name").asText());
52+
5153
return Version.mkUnsafe(json.get("tag_name").asText());
5254
});
5355
}
@@ -57,17 +59,17 @@ private Version fetchLatestIncPreRelease() {
5759
var attempt = 1;
5860

5961
while (true) {
60-
val endpoint = ctx.properties().cliGithubApiReposUrl() + "/releases?per_page=1";
62+
val endpoint = ctx.properties().cliGithubApiReposUrl() + "/releases?per_page=1&page=" + attempt;
6163

6264
val response = HttpUtils.GET(endpoint, c -> c, r -> r);
6365

6466
if (response.statusCode() >= 400 && response.statusCode() != 404) {
6567
throw new AstraCliException(ExitCode.RELEASE_NOT_FOUND, """
6668
@|bold,red An error occurred while fetching the latest release from %s|@
67-
69+
6870
Status:
6971
@!%d!@
70-
72+
7173
Body:
7274
%s
7375
""".formatted(endpoint, response.statusCode(), response.body()));
@@ -81,6 +83,7 @@ private Version fetchLatestIncPreRelease() {
8183
""".formatted(endpoint));
8284
}
8385

86+
// very, very unlikely to happen
8487
if (json.isArray() && json.get(0).get("draft").asBoolean()) {
8588
updateMsg.accept("Resolving latest release of @!astra!@ (attempt %d)".formatted(++attempt));
8689
continue;

0 commit comments

Comments
 (0)