Skip to content

Commit a2806aa

Browse files
authored
Fix astra nuke, some tests, + some other minor things (#246)
* Fix `astra nuke` * Add tenant prompter * Fix tests * Update various descriptions * Some more stuff I don't remember
1 parent 2c74b17 commit a2806aa

File tree

129 files changed

+592
-847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+592
-847
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ build/
77
### IntelliJ IDEA ###
88
.idea/modules.xml
99
.idea/jarRepositories.xml
10+
.idea/workspace.xml
1011
.idea/compiler.xml
12+
.idea/tasks.xml
1113
.idea/libraries/
1214
*.iws
1315
*.iml

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 0 additions & 577 deletions
This file was deleted.

docs_spec.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@
77
"help",
88
"docs"
99
],
10-
"seeAlsoLinks": {
11-
"upgrade": [
12-
"xref:installation.adoc[]"
13-
]
14-
}
10+
"seeAlsoLinks": {}
1511
}

scripts/install.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ echo ""
8282
echo " Installer: $ASTRA_CLI_VERSION"
8383
echo "$RESET"
8484

85+
# Options
86+
AUTO_YES_INSTALL=0
87+
88+
if [ -t 0 ]; then
89+
if [ "${1:-}" = "--yes" ] || [ "${1:-}" = "-y" ]; then
90+
AUTO_YES_INSTALL=1
91+
fi
92+
else
93+
echo "${RED}Error: Script is running in a non-interactive terminal${RESET}"
94+
echo ""
95+
echo "Please use the following command instead to run the script interactively:"
96+
echo ""
97+
renderCommand "sh -c \"\$(curl -fsSL \"https://raw.githubusercontent.com/datastax/astra-cli/main/scripts/install.sh\")\""
98+
echo ""
99+
echo "If you really want to run this script in a non-interactively, pass the ${BLUE}--yes${RESET} flag to accept installing astra in the following location:"
100+
echo "${BLUE}>${RESET} $(underline "$(tildify "$ASTRA_CLI_DIR/")")"
101+
exit 1
102+
fi
103+
85104
# Required tools check
86105
if ! command -v curl >/dev/null 2>&1; then
87106
error "Error: curl is not installed. Please install curl and try again."
@@ -156,6 +175,36 @@ else
156175
checklist "No existing installation found."
157176
fi
158177

178+
# Verify installation path
179+
echo ""
180+
echo "${GREEN}Ready to install Astra CLI ✅${RESET}"
181+
echo ""
182+
echo "Do you want to install Astra CLI to $(underline "$(tildify "$ASTRA_CLI_DIR/")")? ${BLUE}[Y]es/[d]ifferent path/[c]ancel${RESET}"
183+
184+
while [ "$AUTO_YES_INSTALL" = 0 ]; do
185+
printf "%s" "${BLUE}> ${RESET}"
186+
read -r res
187+
188+
case ${res:-y} in
189+
[Yy]* )
190+
for _ in $(seq 1 5); do color cuu1 && color el; done
191+
break;;
192+
[Dd]*)
193+
echo ""
194+
echo "${RED}To use a custom installation path, please globally set the ASTRA_HOME environment variable.${RESET}"
195+
echo ""
196+
echo "This variable $(color bold)must remain in place forever${RESET} (e.g. in your shell profile like $(underline "~/.zprofile"), $(underline "~/.bash_profile"), etc.) so that the CLI can always locate its home directory."
197+
echo ""
198+
echo "After setting it, restart your terminal or run 'source ~/.zprofile' (or the appropriate file) to apply the change."
199+
exit 1
200+
;;
201+
[Cc]* )
202+
error "\nCancelling installation.";;
203+
* )
204+
echo "Please answer ${BLUE}yes${RESET}, ${BLUE}no${RESET}, or ${BLUE}cancel${RESET}.";;
205+
esac
206+
done
207+
159208
# Create installation directory
160209
if mkdir -p "$ASTRA_CLI_DIR"; then
161210
checklist "Using installation dir $(underline "$(tildify "$ASTRA_CLI_DIR/")")${RESET}${LIGHT_GRAY}."

src/main/java/com/dtsx/astra/cli/AstraCli.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ public static <T> T exit(int exitCode) {
223223
public static class SetupExampleProvider implements ExampleProvider {
224224
@Override
225225
public Pair<String, String> get(CliContext ctx) {
226+
226227
try {
227228
val configFileExists = Files.exists(AstraConfig.resolveDefaultAstraConfigFile(ctx));
228229

229-
if (!configFileExists) {
230+
// keeps output deterministic for testing
231+
if (!configFileExists || System.getProperty("cli.testing") != null) {
230232
return Pair.create("Setup the Astra CLI", "${cli.name} setup");
231233
}
232234

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ private void setAnsi(boolean noColor) {
8686
names = { "--spinner" },
8787
description = { "Enable/disable loading spinners", SHOW_CUSTOM_DEFAULT + "enabled if tty" },
8888
negatable = true,
89-
showDefaultValue = Visibility.NEVER,
9089
fallbackValue = "true"
9190
)
9291
private Optional<Boolean> enableSpinner;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@Command(
2424
name = "completions",
2525
aliases = { "compgen" },
26-
description = "See the help for the @|code @{cli.name} shellenv!@ command to setup completions in your shell.",
26+
description = "See the help for the @|code @{cli.name} shellenv|@ command to setup completions in your shell.",
2727
descriptionHeading = "%n",
2828
hidden = true
2929
)

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,23 @@ private OutputAll handleNuked(NukeResult res) {
9292
val summary = new StringBuilder();
9393
val nothingToReport = new ArrayList<String>();
9494

95-
appendToSummary(summary, nothingToReport, "deleted", res.deletedFiles().stream().collect(HashMap::new, (m, v) -> m.put(v, Optional.of(" @|faint (contained binary)|@").filter((_) -> res.cliBinaryPath().startsWith(v))), Map::putAll));
96-
appendToSummary(summary, nothingToReport, "needing updates", res.shellRcFilesToUpdate().stream().collect(HashMap::new, (m, v) -> m.put(v, Optional.empty()), Map::putAll));
97-
appendToSummary(summary, nothingToReport, "skipped", res.skipped().entrySet().stream().collect(HashMap::new, (m, v) -> m.put(v.getKey(), Optional.of(" - " + v.getValue().reason())), Map::putAll));
95+
appendToSummary("Files deleted", summary, nothingToReport, "deleted", res.deletedFiles().stream().collect(HashMap::new, (m, v) -> m.put(v, Optional.of(" @|faint (contained binary)|@").filter((_) -> res.cliBinaryPath().startsWith(v))), Map::putAll));
96+
appendToSummary("Shell profiles containing @!astra!@", summary, nothingToReport, "needing updates", res.shellRcFilesToUpdate().stream().collect(HashMap::new, (m, v) -> m.put(v, Optional.empty()), Map::putAll));
97+
appendToSummary("Files skipped", summary, nothingToReport, "skipped", res.skipped().entrySet().stream().collect(HashMap::new, (m, v) -> m.put(v.getKey(), Optional.of(" - " + v.getValue().reason())), Map::putAll));
9898

9999
switch (nothingToReport.size()) {
100-
case 3 -> summary.append(NL).append("@|faint No files were deleted, updated, or skipped.|@").append(NL);
101-
case 2 -> summary.append(NL).append("@|faint No files ").append(nothingToReport.get(0)).append(" or ").append(nothingToReport.get(1)).append(".|@").append(NL);
102-
case 1 -> summary.append(NL).append("@|faint No files ").append(nothingToReport.get(0)).append(".|@").append(NL);
100+
case 3 -> summary
101+
.append(NL)
102+
.append("@|faint No files were deleted, needing updates, or skipped.|@")
103+
.append(NL);
104+
case 2 -> summary
105+
.append(NL)
106+
.append("@|faint No files ").append(nothingToReport.get(0)).append(" or ").append(nothingToReport.get(1)).append(".|@")
107+
.append(NL);
108+
case 1 -> summary
109+
.append(NL)
110+
.append("@|faint No files ").append(nothingToReport.get(0)).append(".|@")
111+
.append(NL);
103112
}
104113

105114
if (res.skipped().values().stream().anyMatch(s -> s instanceof NeedsSudo)) {
@@ -150,11 +159,11 @@ case BinaryNotWritable(var path) -> """
150159
return trimIndent(str);
151160
}
152161

153-
private void appendToSummary(StringBuilder sb, ArrayList<String> nothingToReport, String header, Map<Path, Optional<String>> files) {
162+
private void appendToSummary(String header, StringBuilder sb, ArrayList<String> nothingToReport, String thingToReport, Map<Path, Optional<String>> files) {
154163
if (files.isEmpty()) {
155-
nothingToReport.add(header);
164+
nothingToReport.add(thingToReport);
156165
} else {
157-
sb.append(NL).append("Files ").append(header).append(":").append(NL);
166+
sb.append(NL).append(header).append(":").append(NL);
158167

159168
for (val file : files.entrySet()) {
160169
sb.append("→ ").append(ctx.highlight(file.getKey()));
@@ -181,7 +190,7 @@ protected Operation<NukeResult> mkOperation() {
181190

182191
private boolean promptShouldDeleteAstrarc(List<Path> files, boolean isDryRun) {
183192
val secondLine = (isDryRun)
184-
? "@|faint This is a dry-run, so the file @|underline will not actually be deleted|@.|@"
193+
? "@|faint (This is a dry-run, so the file|@ @|faint,underline will not actually be deleted.|@@|faint )|@"
185194
: "Your credentials @!may be lost!@ if you do. A backup is recommended.";
186195

187196
val filesStr = new StringJoiner(" and ");

0 commit comments

Comments
 (0)