Skip to content

Commit 9d0e35c

Browse files
authored
1.0.1 fixes (#252)
- [x] Fixes #247 - [x] Fixes #248 - [x] Resolves #249 - [x] Fixes bug with `streaming.exists` returning `true` when it shouldn't - I believe this is a DevOps API bug so I changed the method to use a `findOne` under the hood - [x] Fixed `dsbulk` not downloading properly - This one's on me - [x] Fixed `astra role --help` saying there was no `--help` flag - [x] Minor updates to docs autogeneration - [x] Fix `astra nuke --yes` - [x] Update installer script to make next steps more obvious
1 parent 75ee7dd commit 9d0e35c

25 files changed

+248
-63
lines changed

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"
19+
version = "1.0.1-rc.3"
2020

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

docs_spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"collapsibleOptionGroups" : [
3-
"Command Options",
3+
"Common Options",
44
"Connection Options"
55
],
66
"hideCommands": [

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"
117+
$ASTRA_CLI_VERSION = "1.0.1-rc.3"
118118

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

scripts/install.sh

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
set -eu
44
IFS=$(printf '\n\t')
55

6+
if command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
7+
COLORS_SUPPORTED=true
8+
fi
9+
610
color() {
7-
if command -v tput >/dev/null 2>&1 && [ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]; then
11+
if [ "$COLORS_SUPPORTED" = true ]; then
812
tput "$@"
913
else
1014
printf ""
@@ -37,7 +41,7 @@ renderCommand() {
3741
}
3842

3943
# Constants
40-
ASTRA_CLI_VERSION="1.0.0"
44+
ASTRA_CLI_VERSION="1.0.1-rc.3"
4145

4246
get_astra_dir() {
4347
if [ -n "${ASTRA_HOME:-}" ]; then
@@ -126,22 +130,116 @@ install_url="https://github.com/datastax/astra-cli/releases/download/v$ASTRA_CLI
126130

127131
# Out of order but shh
128132
print_next_steps() {
133+
steps_str=$(mk_print_next_steps_str "$1")
134+
135+
if [ "$COLORS_SUPPORTED" = true ]; then
136+
draw_box_around "$steps_str"
137+
else
138+
printf '%s\n' "$steps_str"
139+
fi
140+
}
141+
142+
draw_box_around() {
143+
max_width=0
144+
while IFS= read -r line; do
145+
visible_len=$(visible_len "$line")
146+
147+
if [ "$visible_len" -gt "$max_width" ]; then
148+
max_width=$visible_len
149+
fi
150+
done <<EOF
151+
$1
152+
EOF
153+
154+
box_width=$((max_width + 6))
155+
border_len=$((box_width - 2))
156+
157+
draw_line "$border_len" "" "" ""
158+
draw_line "$border_len" "" " " ""
159+
160+
while IFS= read -r line; do
161+
padding=$((max_width - $(visible_len "$line")))
162+
draw_line "$padding" "${BLUE}${RESET} ${line}" " " " ${BLUE}${RESET}"
163+
done <<EOF
164+
$1
165+
EOF
166+
167+
draw_line "$border_len" "" " " ""
168+
draw_line "$border_len" "" "" ""
169+
}
170+
171+
# https://stackoverflow.com/a/56170835
172+
visible_len() {
173+
esc=$(printf '\033')
174+
stripped=$(printf '%s' "$1" | sed "s/${esc}[^m]*m//g")
175+
printf '%d' "${#stripped}"
176+
}
177+
178+
draw_line() {
179+
i=0
180+
printf '%s' "${BLUE}${2}"
181+
while [ "$i" -lt "$1" ]; do
182+
printf "$3"
183+
i=$((i + 1))
184+
done
185+
printf '%s\n' "${4}${RESET}"
186+
}
187+
188+
mk_print_next_steps_str() {
189+
echo "$1"
190+
echo ""
191+
129192
if [ $os = "macos" ] && command -v xattr >/dev/null 2>&1 && xattr -l "$EXE_PATH" | grep -q "com.apple.quarantine"; then
130193
renderComment "Run the following to remove the quarantine label from the binary"
131194
renderCommand "xattr -d com.apple.quarantine \"$(tildify "$EXE_PATH")\""
132195
echo ""
133196
fi
134197

135-
renderComment "Append the following to your shell profile (e.g. $(underline "~/.zprofile"), $(underline "~/.bash_profile"), etc.)"
198+
case "${SHELL}" in
199+
*/bash*)
200+
if [ "$os" = linux ]; then
201+
print_append_to_shell_profile "${HOME}/.bashrc"
202+
else
203+
print_append_to_shell_profile "${HOME}/.bash_profile"
204+
fi
205+
;;
206+
*/zsh*)
207+
if [ "$os" = linux ]; then
208+
print_append_to_shell_profile "${ZDOTDIR:-"${HOME}"}/.zshrc"
209+
else
210+
print_append_to_shell_profile "${ZDOTDIR:-"${HOME}"}/.zprofile"
211+
fi
212+
;;
213+
*)
214+
renderComment "Add astra to your PATH in your shell profile"
215+
renderCommand "export PATH=$(dirname \""$(tildify "$EXE_PATH")"\"):\$PATH\""
216+
echo ""
217+
;;
218+
esac
219+
220+
renderComment "Run the following to get started!"
221+
renderCommand "astra setup"
222+
}
223+
224+
print_append_to_shell_profile() {
225+
file="$1"
226+
227+
# shellcheck disable=SC2016
136228
if [ "$ASTRA_CLI_DIR_RESOLVER" = "custom" ]; then
137-
renderCommand "eval \"\$($(tildify "$EXE_PATH") shellenv --home \"$(tildify "$ASTRA_HOME")\")\""
229+
command="eval \"\$($(tildify "$EXE_PATH") shellenv --home \"$(tildify "$ASTRA_HOME")\")\""
138230
else
139-
renderCommand "eval \"\$($(tildify "$EXE_PATH") shellenv)\""
231+
command="eval \"\$($(tildify "$EXE_PATH") shellenv)\""
140232
fi
141-
echo ""
142233

143-
renderComment "Run the following to get started!"
144-
renderCommand "astra setup"
234+
if [ -w "$file" ]; then
235+
renderComment "Run the following to enable completions and update your PATH"
236+
renderCommand "echo '$command' >> $(tildify "$file")"
237+
else
238+
renderComment "Append the following to your $(underline "$(tildify "$file")") to enable completions and update your PATH"
239+
renderCommand "$command"
240+
fi
241+
242+
echo ""
145243
}
146244

147245
# Existing installation checks
@@ -157,10 +255,12 @@ if [ -f "$existing_install_path" ]; then
157255
echo "${BLUE}${LIGHT_GRAY}(< astra-cli 1.x)${RESET} Remove the existing installation manually and re-run this installer."
158256
echo "${BLUE}${LIGHT_GRAY}(> astra-cli 1.x)${RESET} Run ${BLUE}astra upgrade${RESET} to automatically update to the latest version."
159257
echo "${BLUE}${LIGHT_GRAY}(> astra-cli 1.x)${RESET} Run ${BLUE}astra nuke${RESET} to completely remove the CLI and then re-run this installer."
160-
echo ""
161-
echo "If you already knew astra was installed but you can't use it, please make sure you've done the following:"
162-
echo ""
163-
print_next_steps
258+
259+
if command -v astra >/dev/null 2>&1; then
260+
echo ""
261+
print_next_steps "If you just can't use ${BLUE}astra${RESET}, ensure you've done the following:"
262+
fi
263+
164264
exit 1
165265
else
166266
checklist "No existing installation found."
@@ -198,6 +298,4 @@ rm "$TAR_PATH" 2>/dev/null || true
198298
echo ""
199299
echo "${GREEN}Astra CLI installed successfully! 🎉${RESET}"
200300
echo ""
201-
echo "Next steps:"
202-
echo ""
203-
print_next_steps
301+
print_next_steps "Next steps:"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ public static void main(String... args) {
158158

159159
@SneakyThrows
160160
@VisibleForTesting
161+
@SuppressWarnings("unused")
161162
public static int run(Ref<CliContext> ctxRef, String... args) {
162163
@Cleanup val jansi = JansiUtils.installIfNecessary();
163164

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ private String evokeProperExecuteFunction(CliContext ctx) {
188188
}
189189

190190
protected final List<String> originalArgs() {
191-
return listAdd(ctx.properties().cliName(), spec.commandLine().getParseResult().originalArgs());
191+
return listAdd(ctx.properties().cliName(), spec.commandLine().getParseResult().originalArgs()).stream()
192+
.map(s -> s.contains(" ") ? "'" + s + "'" : s)
193+
.toList();
192194
}
193195
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private Profile resolveProfileFromConfigFile(@Nullable Path path, ProfileName ta
185185
}
186186

187187
val profileNamesHint = profileNames.stream()
188+
.map(n -> "'" + n + "'")
188189
.reduce((a, b) -> a + "|" + b)
189190
.orElse("<name>");
190191

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public class NukeCmd extends AbstractCmd<NukeResult> {
6767
@Option(
6868
names = { "--yes", "-y" },
6969
description = "Whether to nuke without confirmation (if not a dry run)",
70-
defaultValue = "false",
71-
fallbackValue = "false"
70+
defaultValue = "false"
7271
)
7372
public boolean $yes;
7473

src/main/java/com/dtsx/astra/cli/commands/config/ConfigCreateCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private OutputAll handleConfigCreated(ProfileCreated result) {
118118
}
119119

120120
return OutputAll.response(creationMessage + mkHint(), data, List.of(
121-
new Hint("Set it as the default profile:", "${cli.name} config use " + result.profileName())
121+
new Hint("Set it as the default profile:", "${cli.name} config use '" + result.profileName() + "'")
122122
));
123123
}
124124

@@ -133,7 +133,7 @@ private <T> T throwProfileAlreadyExists(ProfileName profileName) {
133133
? "The @'!--fail-if-exists!@ flag was set, so the operation failed without confirmation or warning."
134134
: "To overwrite it, either interactively respond @'!yes@! to the prompt, or use the @'!--overwrite!@ option to proceed without confirmation.";
135135

136-
throw new AstraCliException(CONFIG_ALREADY_EXISTS, """
136+
throw new AstraCliException(PROFILE_ALREADY_EXISTS, """
137137
@|bold,red Error: A profile with the name '%s' already exists in the configuration file.|@
138138
139139
%s
@@ -142,7 +142,7 @@ private <T> T throwProfileAlreadyExists(ProfileName profileName) {
142142
mainMsg
143143
), List.of(
144144
new Hint("Example fix:", originalArgsWithoutFailIfExists, "--overwrite"),
145-
new Hint("See the values of the existing profile:", "${cli.name} config get " + profileName)
145+
new Hint("Get the definition of the existing profile:", "${cli.name} config get '" + profileName + "'")
146146
));
147147
}
148148

@@ -152,7 +152,7 @@ private <T> T throwAttemptedToSetDefault() {
152152
: "";
153153

154154
val originalArgsWithoutDefault = originalArgs().stream()
155-
.map((s) -> ProfileName.DEFAULT.unwrap().equals(s) ? "<new_name>" : s)
155+
.map((s) -> s.contains(ProfileName.DEFAULT.unwrap()) ? "<new_name>" : s)
156156
.toList();
157157

158158
throw new AstraCliException(ILLEGAL_OPERATION, """

src/main/java/com/dtsx/astra/cli/commands/config/ConfigGetCmd.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ private String mkKeysMsg(String key, IniSection section) {
147147
key,
148148
section.name(),
149149
section.pairs().stream().map(p -> "- " + ctx.highlight(p.key())).collect(Collectors.joining(NL)),
150-
renderComment(ctx.colors(), "Get the values of the keys in this profile with:"),
151-
renderCommand(ctx.colors(), "${cli.name} config get " + section.name())
150+
renderComment(ctx.colors(), "Get the definition of profile with:"),
151+
renderCommand(ctx.colors(), "${cli.name} config get '" + section.name() + "'")
152152
);
153153
}
154154

0 commit comments

Comments
 (0)