Skip to content

Commit b8422e3

Browse files
committed
v0.1
1 parent f6eeeba commit b8422e3

File tree

6 files changed

+81
-72
lines changed

6 files changed

+81
-72
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<description>Command Line Interface for DataStax Astra</description>
88
<packaging>jar</packaging>
99
<inceptionYear>2022</inceptionYear>
10-
<version>0.2-SNAPSHOT</version>
10+
<version>0.1</version>
1111
<url>https://github.com/datastax/astra-cli</url>
1212
<properties>
1313
<sonar.organization>clun-datastax</sonar.organization>

src/main/dist/astra-install-native.sh renamed to src/main/dist/astra-install-alpha5.sh

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ echo " \/ \/ \/ "
2727
echo " "
2828

2929
# Global variables
30-
ASTRA_CLI_VERSION="0.1.alpha6"
30+
ASTRA_CLI_VERSION="0.1.alpha5"
3131

32-
echo "Installing Astra Cli$(tput setaf 6) $ASTRA_CLI_VERSION $(tput setaf 7) please wait... "
32+
echo "Installing Astra Cli $ASTRA_CLI_VERSION, please wait... "
3333

3434
ASTRA_CLI_PLATFORM=$(uname)
3535
ASTRA_CLI_DIR="$HOME/.astra/cli"
@@ -48,7 +48,7 @@ astra_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"
4848
astra_init_snippet=$( cat << EOF
4949
#THIS MUST BE AT THE END OF THE FILE FOR ASTRA_CLI TO WORK!!!
5050
export ASTRADIR="$ASTRA_CLI_DIR"
51-
[[ -s "${ASTRA_CLI_DIR}/astra-init.sh" ]] && source "${ASTRA_CLI_DIR}/astra-init.sh"
51+
[[ -s "${ASTRA_CLI_DIR}/astra-cli-autocomplete.sh" ]] && source "${ASTRA_CLI_DIR}/astra-cli-autocomplete.sh"
5252
EOF
5353
)
5454

@@ -57,38 +57,24 @@ cygwin=false;
5757
darwin=false;
5858
solaris=false;
5959
freebsd=false;
60-
linux=false;
6160
case "$(uname)" in
6261
CYGWIN*)
6362
cygwin=true
64-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-windows.zip"
65-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-windows.zip"
6663
;;
6764
Darwin*)
6865
darwin=true
69-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-mac.zip"
70-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-mac.zip"
7166
;;
7267
SunOS*)
7368
solaris=true
74-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
75-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
7669
;;
7770
FreeBSD*)
7871
freebsd=true
79-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
80-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
81-
;;
82-
Linux*)
83-
linux=true
84-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
85-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
86-
;;
8772
esac
8873

8974
# Sanity checks
9075
echo ""
91-
echo "$(tput setaf 6)Checking prerequisites:$(tput setaf 7)"
76+
echo "Checking prerequisites:"
77+
9278
if [ -d "$ASTRA_DIR" ]; then
9379
echo ""
9480
echo "======================================================================================================"
@@ -112,6 +98,18 @@ if ! command -v unzip > /dev/null; then
11298
fi
11399
echo "$(tput setaf 2)[OK]$(tput setaf 7) - unzip command is available"
114100

101+
if ! command -v zip > /dev/null; then
102+
echo "Not found."
103+
echo "======================================================================================================"
104+
echo " Please install zip on your system using your favourite package manager."
105+
echo ""
106+
echo " Restart after installing zip."
107+
echo "======================================================================================================"
108+
echo ""
109+
exit 1
110+
fi
111+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - zip command is available"
112+
115113
if ! command -v curl > /dev/null; then
116114
echo "Not found."
117115
echo ""
@@ -126,7 +124,7 @@ fi
126124
echo "$(tput setaf 2)[OK]$(tput setaf 7) - curl command is available"
127125

128126
echo ""
129-
echo "$(tput setaf 6)Preparing directories:$(tput setaf 7)"
127+
echo "Preparing directories:"
130128
mkdir -p "$astra_tmp_folder"
131129
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $astra_tmp_folder"
132130
mkdir -p "$ASTRA_CLI_DIR"
@@ -135,12 +133,14 @@ mkdir -p "$astra_scb_folder"
135133
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $astra_scb_folder"
136134

137135
echo ""
138-
echo "$(tput setaf 6)Downloading archive:$(tput setaf 7)"
136+
echo "Downloading archive:"
137+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}.zip"
138+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}.zip"
139139
if [ -f "$astra_zip_file" ]; then
140140
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Archive is already there"
141141
else
142-
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
143-
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File downloaded"
142+
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
143+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File downloaded"
144144
fi
145145

146146
# check integrity
@@ -155,13 +155,14 @@ if [[ -z "$ARCHIVE_OK" ]]; then
155155
fi
156156
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Integrity of the archive checked"
157157

158+
158159
if [[ "$cygwin" == 'true' ]]; then
159160
astra_tmp_folder=$(cygpath -w "$astra_tmp_folder")
160161
astra_zip_file=$(cygpath -w "$astra_zip_file")
161162
fi
162163

163164
echo ""
164-
echo "$(tput setaf 6)Extracting and installation:$(tput setaf 7)"
165+
echo "Extracting and installation:"
165166
unzip -qo "$astra_zip_file" -d "$astra_tmp_folder"
166167
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Extraction is successful"
167168

@@ -175,36 +176,27 @@ echo "$(tput setaf 2)[OK]$(tput setaf 7) - Installation cleaned up"
175176
if [[ $darwin == true ]]; then
176177
# Adding on MAC OS
177178
touch "$astra_bash_profile"
178-
if [[ -z $(grep 'astra-init.sh' "$astra_bash_profile") ]]; then
179+
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_bash_profile") ]]; then
179180
echo -e "\n$astra_init_snippet" >> "$astra_bash_profile"
180181
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bash_profile}"
181182
fi
182183
else
183184
# Attempt update of interactive bash profile on regular UNIX
184185
touch "${astra_bashrc}"
185-
if [[ -z $(grep 'astra-init.sh' "$astra_bashrc") ]]; then
186+
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_bashrc") ]]; then
186187
echo -e "\n$astra_init_snippet" >> "$astra_bashrc"
187188
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bashrc}"
188189
fi
189190
fi
190191

191192
touch "$astra_zshrc"
192-
if [[ -z $(grep 'astra-init.sh' "$astra_zshrc") ]]; then
193+
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_zshrc") ]]; then
193194
echo -e "\n$astra_init_snippet" >> "$astra_zshrc"
194195
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_zshrc}"
195196
fi
196197

197198
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Installation Successful"
198199
echo ""
199-
if [[ "$darwin" == 'true' ]]; then
200-
echo "+---------------------------------------------------------------------+"
201-
echo "| ⚠️ Mac installation detected |"
202-
echo "| |"
203-
echo "| astra is now a binary |"
204-
echo "| Make sure to $(tput setaf 3)authorize in System Preferences$(tput setaf 7) during first usage |"
205-
echo "+---------------------------------------------------------------------+"
206-
echo ""
207-
fi
208200
echo "Open $(tput setaf 2)A NEW TERMINAL$(tput setaf 7) and run: $(tput setaf 3)astra setup$(tput setaf 7)"
209201
echo ""
210202
echo "You can close this window."

src/main/dist/astra-install.sh

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ echo " \/ \/ \/ "
2727
echo " "
2828

2929
# Global variables
30-
ASTRA_CLI_VERSION="0.1.alpha5"
30+
ASTRA_CLI_VERSION="0.1"
3131

32-
echo "Installing Astra Cli $ASTRA_CLI_VERSION, please wait... "
32+
echo "Installing Astra Cli$(tput setaf 6) $ASTRA_CLI_VERSION $(tput setaf 7) please wait... "
3333

3434
ASTRA_CLI_PLATFORM=$(uname)
3535
ASTRA_CLI_DIR="$HOME/.astra/cli"
@@ -48,7 +48,7 @@ astra_zshrc="${ZDOTDIR:-${HOME}}/.zshrc"
4848
astra_init_snippet=$( cat << EOF
4949
#THIS MUST BE AT THE END OF THE FILE FOR ASTRA_CLI TO WORK!!!
5050
export ASTRADIR="$ASTRA_CLI_DIR"
51-
[[ -s "${ASTRA_CLI_DIR}/astra-cli-autocomplete.sh" ]] && source "${ASTRA_CLI_DIR}/astra-cli-autocomplete.sh"
51+
[[ -s "${ASTRA_CLI_DIR}/astra-init.sh" ]] && source "${ASTRA_CLI_DIR}/astra-init.sh"
5252
EOF
5353
)
5454

@@ -57,24 +57,38 @@ cygwin=false;
5757
darwin=false;
5858
solaris=false;
5959
freebsd=false;
60+
linux=false;
6061
case "$(uname)" in
6162
CYGWIN*)
6263
cygwin=true
64+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-windows.zip"
65+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-windows.zip"
6366
;;
6467
Darwin*)
6568
darwin=true
69+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-mac.zip"
70+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-mac.zip"
6671
;;
6772
SunOS*)
6873
solaris=true
74+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
75+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
6976
;;
7077
FreeBSD*)
7178
freebsd=true
79+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
80+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
81+
;;
82+
Linux*)
83+
linux=true
84+
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
85+
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}-linux.zip"
86+
;;
7287
esac
7388

7489
# Sanity checks
7590
echo ""
76-
echo "Checking prerequisites:"
77-
91+
echo "$(tput setaf 6)Checking prerequisites:$(tput setaf 7)"
7892
if [ -d "$ASTRA_DIR" ]; then
7993
echo ""
8094
echo "======================================================================================================"
@@ -98,18 +112,6 @@ if ! command -v unzip > /dev/null; then
98112
fi
99113
echo "$(tput setaf 2)[OK]$(tput setaf 7) - unzip command is available"
100114

101-
if ! command -v zip > /dev/null; then
102-
echo "Not found."
103-
echo "======================================================================================================"
104-
echo " Please install zip on your system using your favourite package manager."
105-
echo ""
106-
echo " Restart after installing zip."
107-
echo "======================================================================================================"
108-
echo ""
109-
exit 1
110-
fi
111-
echo "$(tput setaf 2)[OK]$(tput setaf 7) - zip command is available"
112-
113115
if ! command -v curl > /dev/null; then
114116
echo "Not found."
115117
echo ""
@@ -124,7 +126,7 @@ fi
124126
echo "$(tput setaf 2)[OK]$(tput setaf 7) - curl command is available"
125127

126128
echo ""
127-
echo "Preparing directories:"
129+
echo "$(tput setaf 6)Preparing directories:$(tput setaf 7)"
128130
mkdir -p "$astra_tmp_folder"
129131
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $astra_tmp_folder"
130132
mkdir -p "$ASTRA_CLI_DIR"
@@ -133,14 +135,12 @@ mkdir -p "$astra_scb_folder"
133135
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Created $astra_scb_folder"
134136

135137
echo ""
136-
echo "Downloading archive:"
137-
download_url="https://github.com/datastax/astra-cli/releases/download/${ASTRA_CLI_VERSION}/astra-cli-${ASTRA_CLI_VERSION}.zip"
138-
astra_zip_file="${astra_tmp_folder}/astra-cli-${ASTRA_CLI_VERSION}.zip"
138+
echo "$(tput setaf 6)Downloading archive:$(tput setaf 7)"
139139
if [ -f "$astra_zip_file" ]; then
140140
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Archive is already there"
141141
else
142-
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
143-
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File downloaded"
142+
curl --fail --location --progress-bar "$download_url" > "$astra_zip_file"
143+
echo "$(tput setaf 2)[OK]$(tput setaf 7) - File downloaded"
144144
fi
145145

146146
# check integrity
@@ -155,14 +155,13 @@ if [[ -z "$ARCHIVE_OK" ]]; then
155155
fi
156156
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Integrity of the archive checked"
157157

158-
159158
if [[ "$cygwin" == 'true' ]]; then
160159
astra_tmp_folder=$(cygpath -w "$astra_tmp_folder")
161160
astra_zip_file=$(cygpath -w "$astra_zip_file")
162161
fi
163162

164163
echo ""
165-
echo "Extracting and installation:"
164+
echo "$(tput setaf 6)Extracting and installation:$(tput setaf 7)"
166165
unzip -qo "$astra_zip_file" -d "$astra_tmp_folder"
167166
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Extraction is successful"
168167

@@ -176,27 +175,36 @@ echo "$(tput setaf 2)[OK]$(tput setaf 7) - Installation cleaned up"
176175
if [[ $darwin == true ]]; then
177176
# Adding on MAC OS
178177
touch "$astra_bash_profile"
179-
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_bash_profile") ]]; then
178+
if [[ -z $(grep 'astra-init.sh' "$astra_bash_profile") ]]; then
180179
echo -e "\n$astra_init_snippet" >> "$astra_bash_profile"
181180
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bash_profile}"
182181
fi
183182
else
184183
# Attempt update of interactive bash profile on regular UNIX
185184
touch "${astra_bashrc}"
186-
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_bashrc") ]]; then
185+
if [[ -z $(grep 'astra-init.sh' "$astra_bashrc") ]]; then
187186
echo -e "\n$astra_init_snippet" >> "$astra_bashrc"
188187
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_bashrc}"
189188
fi
190189
fi
191190

192191
touch "$astra_zshrc"
193-
if [[ -z $(grep 'astra-cli-autocomplete.sh' "$astra_zshrc") ]]; then
192+
if [[ -z $(grep 'astra-init.sh' "$astra_zshrc") ]]; then
194193
echo -e "\n$astra_init_snippet" >> "$astra_zshrc"
195194
echo "$(tput setaf 2)[OK]$(tput setaf 7) - astra added to ${astra_zshrc}"
196195
fi
197196

198197
echo "$(tput setaf 2)[OK]$(tput setaf 7) - Installation Successful"
199198
echo ""
199+
if [[ "$darwin" == 'true' ]]; then
200+
echo "+---------------------------------------------------------------------+"
201+
echo "| ⚠️ Mac installation detected |"
202+
echo "| |"
203+
echo "| astra is now a binary |"
204+
echo "| Make sure to $(tput setaf 3)authorize in System Preferences$(tput setaf 7) during first usage |"
205+
echo "+---------------------------------------------------------------------+"
206+
echo ""
207+
fi
200208
echo "Open $(tput setaf 2)A NEW TERMINAL$(tput setaf 7) and run: $(tput setaf 3)astra setup$(tput setaf 7)"
201209
echo ""
202210
echo "You can close this window."

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.dtsx.astra.cli.streaming.exception.TenantAlreadyExistException;
5050
import com.dtsx.astra.cli.streaming.exception.TenantNotFoundException;
5151
import com.dtsx.astra.cli.streaming.pulsarshell.PulsarShellCmd;
52+
import com.dtsx.astra.cli.utils.AstraCliUtils;
5253
import com.github.rvesse.airline.Cli;
5354
import com.github.rvesse.airline.annotations.Group;
5455
import com.github.rvesse.airline.help.Help;
@@ -155,7 +156,10 @@ public class AstraCli {
155156
public static void main(String[] args) {
156157
// Enable Colors in terminal
157158
AnsiConsole.systemInstall();
158-
159+
160+
// Create ~/.astra and required sub folders
161+
AstraCliUtils.createHomeAstraFolders();
162+
159163
// Parse command
160164
ExitCode code = run(AstraCli.class, args);
161165

src/main/java/com/dtsx/astra/cli/db/cqlsh/CqlShellService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,11 @@ private CqlShellService() {
8686
AstraCliUtils.readProperty("cqlsh.url"),
8787
AstraCliUtils.readProperty("cqlsh.tarball"));
8888

89-
//settings = new CqlShellConfig(
90-
// "https://downloads.datastax.com/enterprise/cqlsh-astra.tar.gz",
91-
// "cqlsh-astra.tar.gz");
92-
9389
cqlshLocalFolder = new File(AstraCliUtils.ASTRA_HOME + File.separator + "cqlsh-astra");
9490

9591
cqlshExecutable = cqlshLocalFolder.getAbsolutePath() + File.separator + "bin" + File.separator + "cqlsh";
9692
}
97-
93+
9894
/**
9995
* Check if cqlshell has been installed.
10096
*

src/main/java/com/dtsx/astra/cli/utils/AstraCliUtils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,14 @@ public static String readProperty(String key) {
102102
}
103103
return properties.getProperty(key);
104104
}
105-
105+
106+
/**
107+
* Initialization of the folders at startup
108+
*/
109+
public static void createHomeAstraFolders() {
110+
File install = new File(ASTRA_HOME);
111+
if (!install.exists()) install.mkdirs();
112+
File folderSCB = new File(ASTRA_HOME + File.separator + SCB_FOLDER);
113+
if (!folderSCB.exists()) folderSCB.mkdirs();
114+
}
106115
}

0 commit comments

Comments
 (0)