Skip to content

Commit 3f949aa

Browse files
committed
Fixing jar, show commands as groupd, autocompletion on
1 parent a10c07e commit 3f949aa

File tree

14 files changed

+209
-96
lines changed

14 files changed

+209
-96
lines changed

astra-shell/dependency-reduced-pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<version>0.3.1-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
9-
<artifactId>astra-sh</artifactId>
9+
<artifactId>astra-shell</artifactId>
1010
<name>+ astra-shell</name>
1111
<build>
1212
<pluginManagement>
@@ -44,7 +44,7 @@
4444
<shadedArtifactAttached>true</shadedArtifactAttached>
4545
<transformers>
4646
<transformer>
47-
<mainClass>com.datastax.astra.AstraShell</mainClass>
47+
<mainClass>com.datastax.astra.shell.AstraCli</mainClass>
4848
</transformer>
4949
</transformers>
5050
<filters>
@@ -102,6 +102,7 @@
102102
</dependency>
103103
</dependencies>
104104
<properties>
105+
<airline.version>2.7.2</airline.version>
105106
<commons-cli.version>1.5.0</commons-cli.version>
106107
<maven-plugin-exec.version>3.0.0</maven-plugin-exec.version>
107108
<jansi.version>2.4.0</jansi.version>

astra-shell/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<properties>
1717
<jansi.version>2.4.0</jansi.version>
18-
<airline.version>2.7.2</airline.version>
18+
<airline.version>2.8.5</airline.version>
1919
<commons-cli.version>1.5.0</commons-cli.version>
2020
<commons-lang.version>3.12.0</commons-lang.version>
2121
<maven-plugin-exec.version>3.0.0</maven-plugin-exec.version>
@@ -30,9 +30,9 @@
3030
<version>${airline.version}</version>
3131
</dependency>
3232
<dependency>
33-
<groupId>commons-cli</groupId>
34-
<artifactId>commons-cli</artifactId>
35-
<version>${commons-cli.version}</version>
33+
<groupId>com.github.rvesse</groupId>
34+
<artifactId>airline-help-bash</artifactId>
35+
<version>${airline.version}</version>
3636
</dependency>
3737

3838
<!-- Leveraging SDK for Astra Accesses -->
@@ -115,7 +115,7 @@
115115
<transformers>
116116
<transformer
117117
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
118-
<mainClass>com.datastax.astra.AstraShell</mainClass>
118+
<mainClass>com.datastax.astra.shell.AstraCli</mainClass>
119119
</transformer>
120120
</transformers>
121121
<filters>

astra-shell/src/main/java/com/datastax/astra/shell/AstraCli.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.datastax.astra.shell;
22

3-
import com.datastax.astra.shell.cmd.ReplCommand;
43
import com.datastax.astra.shell.cmd.HelpCustomCommand;
4+
import com.datastax.astra.shell.cmd.ReplCommand;
55
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand;
66
import com.datastax.astra.shell.cmd.db.ShowOrganizationsCommand;
7+
import com.datastax.astra.shell.cmd.db.ShowOrganizationsCommand;
78
import com.datastax.astra.shell.utils.ShellPrinter;
89
import com.github.rvesse.airline.annotations.Cli;
10+
import com.github.rvesse.airline.annotations.Group;
911

1012
/**
1113
* Main class for the program. Will route commands to proper class
@@ -18,10 +20,16 @@
1820
defaultCommand = ReplCommand.class, // no command provided => REPL
1921
commands = {
2022
ReplCommand.class,
21-
ShowDatabasesCommand.class,
22-
ShowOrganizationsCommand.class,
2323
HelpCustomCommand.class
24-
})
24+
},
25+
26+
groups = {
27+
@Group(
28+
name = "show",
29+
description = "Listing details of an entity or entity list",
30+
commands = { ShowOrganizationsCommand.class, ShowDatabasesCommand.class }
31+
)
32+
})
2533
public class AstraCli {
2634

2735
/**

astra-shell/src/main/java/com/datastax/astra/shell/cmd/ConnectCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
/**
2020
* Connection to another organization.
2121
*
22+
*
23+
* connect --org mdddd
24+
*
2225
* @author Cedrick LUNVEN (@clunven)
2326
*/
2427
@Command(name = "connect", description = "Connect to another Astra instance")

astra-shell/src/main/java/com/datastax/astra/shell/cmd/ReplCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
* @author Cedrick LUNVEN (@clunven)
1616
*/
1717
@Command(
18-
name = "<empty>",
19-
description = "Enter interactive mode if no command provided")
18+
name = ".",
19+
description = "If no command, entering interactive mode.")
2020
public class ReplCommand extends BaseCommand<ReplCommand> implements Runnable {
2121

2222
/** {@inheritDoc} */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.datastax.astra.shell.cmd.db;
2+
3+
import com.datastax.astra.shell.cmd.ConnectCommand;
4+
import com.github.rvesse.airline.annotations.Cli;
5+
import com.github.rvesse.airline.annotations.Group;
6+
import com.github.rvesse.airline.help.Help;
7+
8+
@Cli(
9+
name = "cli",
10+
description = "A simple CLI with several commands available in groups",
11+
groups = {
12+
@Group(
13+
name = "basic",
14+
description = "Basic commands",
15+
commands = { ConnectCommand.class , Help.class}
16+
),
17+
@Group(
18+
name = "show",
19+
description = "Commands that demonstrate option inheritance",
20+
commands = { ShowOrganizationsCommand.class, ShowDatabasesCommand.class }
21+
)
22+
},
23+
commands = { Help.class }
24+
)
25+
public class ShowCommandGroup {
26+
27+
}

astra-shell/src/main/java/com/datastax/astra/shell/cmd/db/ShowDatabasesCommand.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
*
1515
* @author Cedrick LUNVEN (@clunven)
1616
*/
17-
@Command(name = "show-dbs", description = "Display the list of Databases in an organization")
17+
@Command(name = "dbs", description = "Display the list of Databases in an organization")
1818
public class ShowDatabasesCommand extends BaseCommand<ShowDatabasesCommand> {
1919

2020
/** {@inheritDoc} */
2121
public void execute() {
22+
ShellContext.getInstance().getAstraClient()
23+
.apiDevopsDatabases().databases();
24+
25+
2226
// Setup Tableshow
2327
ShellTable sht = new ShellTable();
2428
sht.setColumnTitlesColor(TextColor.YELLOW);

astra-shell/src/main/java/com/datastax/astra/shell/cmd/db/ShowOrganizationsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.datastax.astra.shell.utils.ShellTable;
1010
import com.github.rvesse.airline.annotations.Command;
1111

12-
@Command(name = "show-orgs", description = "Display the list organizations registered in config file")
12+
@Command(name = "orgs", description = "Display the list organizations registered in config file")
1313
public class ShowOrganizationsCommand implements Runnable {
1414

1515
/** {@inheritDoc} */

astra-shell/src/main/resources/astra

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# myapp
3+
4+
source ./completions.bash
5+
6+
java -jar ../../../target/astra-shell-0.3.1-SNAPSHOT-shaded.jar "$@"
7+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
# Generated by airline BashCompletionGenerator
4+
5+
containsElement () {
6+
# This function from http://stackoverflow.com/a/8574392/107591
7+
local e
8+
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
9+
return 1
10+
}
11+
12+
function _complete_astra_command_showdbs() {
13+
# Get completion data
14+
COMPREPLY=()
15+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
16+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
17+
COMMANDS=$1
18+
19+
FLAG_OPTS="--help -v --verbose -h"
20+
ARG_OPTS="--token -org -t --organization"
21+
22+
$( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )
23+
SAW_ARG=$?
24+
if [[ ${SAW_ARG} -eq 0 ]]; then
25+
ARG_VALUES=
26+
ARG_GENERATED_VALUES=
27+
case ${PREV_WORD} in
28+
-org|--organization)
29+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
30+
echo ${COMPREPLY[@]}
31+
return 0
32+
;;
33+
-t|--token)
34+
COMPREPLY=( $(compgen -W "${ARG_VALUES} ${ARG_GENERATED_VALUES}" -- ${CURR_WORD}) )
35+
echo ${COMPREPLY[@]}
36+
return 0
37+
;;
38+
esac
39+
fi
40+
41+
ARGUMENTS=
42+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
43+
echo ${COMPREPLY[@]}
44+
return 0
45+
}
46+
47+
function _complete_astra_command_showorgs() {
48+
# Get completion data
49+
COMPREPLY=()
50+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
51+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
52+
COMMANDS=$1
53+
54+
FLAG_OPTS=""
55+
ARG_OPTS=""
56+
57+
ARGUMENTS=
58+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
59+
echo ${COMPREPLY[@]}
60+
return 0
61+
}
62+
63+
function _complete_astra_command_help() {
64+
# Get completion data
65+
COMPREPLY=()
66+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
67+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
68+
COMMANDS=$1
69+
70+
FLAG_OPTS=""
71+
ARG_OPTS=""
72+
73+
ARGUMENTS=
74+
COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${ARGUMENTS}" -- ${CURR_WORD}) )
75+
echo ${COMPREPLY[@]}
76+
return 0
77+
}
78+
79+
function _complete_astra() {
80+
# Get completion data
81+
CURR_WORD=${COMP_WORDS[COMP_CWORD]}
82+
PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
83+
CURR_CMD=
84+
if [[ ${COMP_CWORD} -ge 1 ]]; then
85+
CURR_CMD=${COMP_WORDS[1]}
86+
fi
87+
88+
COMMANDS="help show-orgs show-dbs"
89+
if [[ ${COMP_CWORD} -eq 1 ]]; then
90+
COMPREPLY=( $(_complete_astra_command_help "${COMMANDS}" ) )
91+
DEFAULT_COMMAND_COMPLETIONS=(${COMPREPLY[@]})
92+
COMPREPLY=()
93+
COMPREPLY=( $(compgen -W "${COMMANDS} ${DEFAULT_COMMAND_COMPLETIONS}" -- ${CURR_WORD}) )
94+
return 0
95+
fi
96+
97+
case ${CURR_CMD} in
98+
show-dbs)
99+
COMPREPLY=( $(_complete_astra_command_showdbs "${COMMANDS}" ) )
100+
return $?
101+
;;
102+
show-orgs)
103+
COMPREPLY=( $(_complete_astra_command_showorgs "${COMMANDS}" ) )
104+
return $?
105+
;;
106+
help)
107+
COMPREPLY=( $(_complete_astra_command_help "${COMMANDS}" ) )
108+
return $?
109+
;;
110+
esac
111+
112+
}
113+
114+
complete -F _complete_astra astra

0 commit comments

Comments
 (0)