Skip to content

Commit 9785572

Browse files
committed
Move list regions, Fix error messages, fix header true, add download counts to readme
1 parent e19094c commit 9785572

24 files changed

+142
-317
lines changed

README.MD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Astra CLI
22

33
[![License Apache2](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
4+
![Latest Release](https://img.shields.io/github/v/release/datastax/astra-cli)
45

56
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=clun_astra-cli)
67
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=clun_astra-cli)
@@ -9,7 +10,6 @@
910
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=clun_astra-cli)
1011
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=bugs)](https://sonarcloud.io/summary/new_code?id=clun_astra-cli)
1112
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=coverage)](https://sonarcloud.io/summary/new_code?id=clun_astra-cli)
12-
![CLI - Continuous Integration](https://github.com/datastax/astra-cli/actions/workflows/cli-native-images.yml/badge.svg)
1313

1414
Astra CLI provides a command line interface in a terminal to operate Datastax Astra. The goal is to offer access to any feature without accessing the user interface. The component is still under development (version `0.1.alpha5`), it will keep moving before the release GA.
1515

@@ -102,5 +102,7 @@ git push
102102
mvn clean -DskipTests -Darguments=-DskipTests release:prepare release:perform
103103
```
104104

105+
![downloads](https://img.shields.io/github/downloads/datastax/astra-cli/total)
106+
105107
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-cli&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=clun_astra-cli)
106108

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.1</version>
10+
<version>0.1.1</version>
1111
<url>https://github.com/datastax/astra-cli</url>
1212
<properties>
1313
<sonar.organization>clun-datastax</sonar.organization>

release.sh

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

src/main/dist/astra-init.sh

Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ function _complete_astra_group_db() {
550550
CURR_CMD=${COMP_WORDS[2]}
551551
fi
552552

553-
COMMANDS="resume list-keyspaces download-scb dsbulk count create-dotenv list delete create-keyspace load get unload create cqlsh status"
553+
COMMANDS="resume list-keyspaces download-scb count create-dotenv list delete create-keyspace load get unload create cqlsh status"
554554
if [[ ${COMP_CWORD} -eq 2 ]]; then
555555
COMPREPLY=( $(_complete_astra_group_db_command_list "${COMMANDS}" ) )
556556
DEFAULT_GROUP_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
@@ -625,11 +625,6 @@ function _complete_astra_group_db() {
625625
echo ${COMPREPLY[@]}
626626
return $?
627627
;;
628-
dsbulk)
629-
COMPREPLY=( $(_complete_astra_group_db_command_dsbulk "${COMMANDS}" ) )
630-
echo ${COMPREPLY[@]}
631-
return $?
632-
;;
633628
cqlsh)
634629
COMPREPLY=( $(_complete_astra_group_db_command_cqlsh "${COMMANDS}" ) )
635630
echo ${COMPREPLY[@]}
@@ -1160,8 +1155,8 @@ function _complete_astra_group_db_command_count() {
11601155
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
11611156
COMMANDS=$1
11621157

1163-
FLAG_OPTS="--no-color -header -v --verbose"
1164-
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
1158+
FLAG_OPTS="--no-color -v --verbose"
1159+
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -header -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
11651160

11661161
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
11671162
SAW_ARG=$?
@@ -1219,6 +1214,11 @@ function _complete_astra_group_db_command_count() {
12191214
echo ${COMPREPLY[@]}
12201215
return 0
12211216
;;
1217+
-header)
1218+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1219+
echo ${COMPREPLY[@]}
1220+
return 0
1221+
;;
12221222
-delim)
12231223
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
12241224
echo ${COMPREPLY[@]}
@@ -1265,8 +1265,8 @@ function _complete_astra_group_db_command_load() {
12651265
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
12661266
COMMANDS=$1
12671267

1268-
FLAG_OPTS="--no-color -dryRun -header -v --verbose"
1269-
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
1268+
FLAG_OPTS="--no-color -dryRun -v --verbose"
1269+
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -header -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
12701270

12711271
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
12721272
SAW_ARG=$?
@@ -1324,6 +1324,11 @@ function _complete_astra_group_db_command_load() {
13241324
echo ${COMPREPLY[@]}
13251325
return 0
13261326
;;
1327+
-header)
1328+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1329+
echo ${COMPREPLY[@]}
1330+
return 0
1331+
;;
13271332
-delim)
13281333
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
13291334
echo ${COMPREPLY[@]}
@@ -1370,8 +1375,8 @@ function _complete_astra_group_db_command_unload() {
13701375
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
13711376
COMMANDS=$1
13721377

1373-
FLAG_OPTS="--no-color -header -v --verbose"
1374-
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
1378+
FLAG_OPTS="--no-color -v --verbose"
1379+
ARG_OPTS="--token -m --keyspace --config-file -o -maxErrors -encoding -t -skipRecords --config -cf -url --dsbulk-config -header -delim --schema.query -maxConcurrentQueries -conf -logDir --table --schema.mapping -k --output"
13751380

13761381
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
13771382
SAW_ARG=$?
@@ -1429,6 +1434,11 @@ function _complete_astra_group_db_command_unload() {
14291434
echo ${COMPREPLY[@]}
14301435
return 0
14311436
;;
1437+
-header)
1438+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1439+
echo ${COMPREPLY[@]}
1440+
return 0
1441+
;;
14321442
-delim)
14331443
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
14341444
echo ${COMPREPLY[@]}
@@ -1468,51 +1478,6 @@ function _complete_astra_group_db_command_unload() {
14681478
return 0
14691479
}
14701480

1471-
function _complete_astra_group_db_command_dsbulk() {
1472-
# Get completion data
1473-
COMPREPLY=()
1474-
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
1475-
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
1476-
COMMANDS=$1
1477-
1478-
FLAG_OPTS="--no-color -v --verbose"
1479-
ARG_OPTS="--token -cf --config-file -o -conf --config --output"
1480-
1481-
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
1482-
SAW_ARG=$?
1483-
if [[ ${SAW_ARG} -eq 0 ]]; then
1484-
ARG_VALUES=
1485-
ARG_GENERATED_VALUES=
1486-
case ${PREV_WORD} in
1487-
--token)
1488-
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1489-
echo ${COMPREPLY[@]}
1490-
return 0
1491-
;;
1492-
-cf|--config-file)
1493-
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1494-
echo ${COMPREPLY[@]}
1495-
return 0
1496-
;;
1497-
-conf|--config)
1498-
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1499-
echo ${COMPREPLY[@]}
1500-
return 0
1501-
;;
1502-
-o|--output)
1503-
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
1504-
echo ${COMPREPLY[@]}
1505-
return 0
1506-
;;
1507-
esac
1508-
fi
1509-
1510-
ARGUMENTS=
1511-
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
1512-
echo ${COMPREPLY[@]}
1513-
return 0
1514-
}
1515-
15161481
function _complete_astra_group_db_command_cqlsh() {
15171482
# Get completion data
15181483
COMPREPLY=()

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

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.dtsx.astra.cli.db.*;
3232
import com.dtsx.astra.cli.db.cqlsh.DbCqlShellCmd;
3333
import com.dtsx.astra.cli.db.dsbulk.DbCountCmd;
34-
import com.dtsx.astra.cli.db.dsbulk.DbDsBulkCmd;
3534
import com.dtsx.astra.cli.db.dsbulk.DbLoadCmd;
3635
import com.dtsx.astra.cli.db.dsbulk.DbUnLoadCmd;
3736
import com.dtsx.astra.cli.db.exception.DatabaseNameNotUniqueException;
@@ -57,7 +56,6 @@
5756
import org.fusesource.jansi.AnsiConsole;
5857

5958
import java.util.Arrays;
60-
import java.util.List;
6159

6260
/**
6361
* Main class for the program. Will route commands to proper class
@@ -88,9 +86,7 @@
8886
defaultCommand = OrgCmd.class,
8987
commands = {
9088
OrgIdCmd.class,
91-
OrgNameCmd.class,
92-
OrgListRegionsDbClassicCmd.class,
93-
OrgListRegionsServerlessCmd.class
89+
OrgNameCmd.class
9490
}),
9591

9692
@Group(
@@ -107,9 +103,11 @@
107103
// Keyspaces
108104
DbCreateKeyspaceCmd.class, DbListKeyspacesCmd.class,
109105
// DsBulk
110-
DbCountCmd.class, DbLoadCmd.class, DbUnLoadCmd.class, DbDsBulkCmd.class,
106+
DbCountCmd.class, DbLoadCmd.class, DbUnLoadCmd.class,
111107
// Cqlshell
112108
DbCqlShellCmd.class,
109+
// List Regions
110+
DbListRegionsClassicCmd.class, DbListRegionsServerlessCmd.class
113111
}),
114112

115113
@Group(
@@ -200,18 +198,20 @@ public static ExitCode run(Class<?> clazz, String[] args) {
200198
ParseArgumentsMissingException |
201199
ParseTooManyArgumentsException |
202200
ParseOptionGroupException ex) {
203-
LoggerShell.exception(ex, getInvalidCmd(args), null);
201+
LoggerShell.exception(ex,
202+
"You provided unknown or not well formatted argument.");
204203
return ExitCode.INVALID_ARGUMENT;
205-
} catch(ParseOptionIllegalValueException |
206-
ParseOptionMissingException ex) {
207-
LoggerShell.exception(ex, getCmd(args), null);
204+
} catch(ParseOptionIllegalValueException | ParseOptionMissingException ex) {
205+
LoggerShell.exception(ex,
206+
"You provided unknown or not well formatted option. (-option)");
208207
return ExitCode.INVALID_OPTION;
209-
} catch(ParseRestrictionViolatedException |
210-
ParseOptionConversionException ex) {
211-
LoggerShell.exception(ex, getCmd(args), null);
208+
} catch(ParseRestrictionViolatedException | ParseOptionConversionException ex) {
209+
LoggerShell.exception(ex,
210+
"You provided an invalid value for option. (-option)");
212211
return ExitCode.INVALID_OPTION_VALUE;
213212
} catch(ParseException ex) {
214-
LoggerShell.exception(ex, getCmd(args), null);
213+
LoggerShell.exception(ex,
214+
"Command is not properly formatted.");
215215
return ExitCode.UNRECOGNIZED_COMMAND;
216216
} catch (InvalidTokenException | TokenNotFoundException |
217217
FileSystemException | ConfigurationException e) {
@@ -239,48 +239,4 @@ public static ExitCode run(Class<?> clazz, String[] args) {
239239
}
240240
}
241241

242-
/**
243-
* Extract commands without options from command line.
244-
*
245-
* @param args
246-
* arguments
247-
* @return
248-
* first part of command line
249-
*/
250-
public static String getCmd(String[] args) {
251-
List <String > listArgs = Arrays.asList(args);
252-
boolean firstOption = false;
253-
int idx = 0;
254-
while (!firstOption && idx < listArgs.size()) {
255-
firstOption = listArgs.get(idx).startsWith("-");
256-
idx++;
257-
}
258-
if (firstOption) {
259-
idx--;
260-
}
261-
return String.join(" ", listArgs.subList(0, idx));
262-
}
263-
264-
/**
265-
* Extract commands without options from command line.
266-
*
267-
* @param args
268-
* arguments
269-
* @return
270-
* first part of command line
271-
*/
272-
public static String getInvalidCmd(String[] args) {
273-
List <String > listArgs = Arrays.asList(args);
274-
boolean firstOption = false;
275-
int idx = 0;
276-
while (!firstOption && idx < listArgs.size()) {
277-
firstOption = listArgs.get(idx).startsWith("-");
278-
idx++;
279-
}
280-
if (firstOption) {
281-
idx--;
282-
}
283-
return String.join(" ", listArgs.subList(0, idx-1));
284-
}
285-
286242
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,14 @@ public void execute() {
5151
if (tokenParam == null || tokenParam.isBlank()) {
5252
verbose = true;
5353
String token;
54-
AstraCliConsole.println(" _____ __ ", Ansi.Color.YELLOW);
55-
AstraCliConsole.println(" / _ \\ _______/ |_____________ ", Ansi.Color.YELLOW);
56-
AstraCliConsole.println(" / /_\\ \\ / ___/\\ __\\_ __ \\__ \\ ", Ansi.Color.YELLOW);
57-
AstraCliConsole.println(" / | \\\\___ \\ | | | | \\// __ \\_", Ansi.Color.YELLOW);
58-
AstraCliConsole.println(" \\____|__ /____ > |__| |__| (____ /", Ansi.Color.YELLOW);
59-
AstraCliConsole.println(" \\/ \\/ \\/\n", Ansi.Color.YELLOW);
60-
54+
AstraCliConsole.banner();
6155
try(Scanner scanner = new Scanner(System.in)) {
6256
boolean valid_token = false;
6357
while (!valid_token) {
64-
AstraCliConsole.println(" ------------------------", Ansi.Color.CYAN);
65-
AstraCliConsole.println(" --- SETUP ---", Ansi.Color.CYAN);
66-
AstraCliConsole.println(" ------------------------\n", Ansi.Color.CYAN);
67-
AstraCliConsole.println("🔑 Enter token (starting with AstraCS...):", Ansi.Color.YELLOW);
58+
AstraCliConsole.println(" -----------------------", Ansi.Color.CYAN);
59+
AstraCliConsole.println(" --- SETUP ---", Ansi.Color.CYAN);
60+
AstraCliConsole.println(" -----------------------\n",Ansi.Color.CYAN);
61+
AstraCliConsole.println("$ Enter an Astra token:", Ansi.Color.CYAN);
6862
token = scanner.nextLine();
6963
if (!token.startsWith("AstraCS:")) {
7064
LoggerShell.error("Your token should start with 'AstraCS:'");

src/main/java/com/dtsx/astra/cli/core/DefaultCmd.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
* #L%
2121
*/
2222

23-
import static com.dtsx.astra.cli.core.out.AstraCliConsole.println;
24-
2523
import com.dtsx.astra.cli.core.out.AstraCliConsole;
2624
import com.dtsx.astra.cli.core.out.StringBuilderAnsi;
2725
import com.dtsx.astra.cli.utils.AstraCliUtils;

0 commit comments

Comments
 (0)