Skip to content

Commit 695af2b

Browse files
committed
more commands
1 parent dd63b55 commit 695af2b

File tree

10 files changed

+62
-62
lines changed

10 files changed

+62
-62
lines changed
File renamed without changes.

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.datastax.astra.shell.cmd.config.ConfigDelete;
99
import com.datastax.astra.shell.cmd.config.ConfigList;
1010
import com.datastax.astra.shell.cmd.config.ConfigShow;
11-
import com.datastax.astra.shell.cmd.config.Setup;
11+
import com.datastax.astra.shell.cmd.config.ConfigSetup;
1212
import com.datastax.astra.shell.cmd.db.DbCreateCli;
1313
import com.datastax.astra.shell.cmd.db.DbDeleteCli;
1414
import com.datastax.astra.shell.cmd.db.DbListCli;
@@ -36,41 +36,39 @@
3636
description = "CLI for DataStax Astra™ including an interactive mode",
3737
defaultCommand = ShellCommand.class, // no command => interactive
3838
commands = {
39-
Setup.class,
39+
ConfigSetup.class,
4040
HelpCommand.class,
4141
ShellCommand.class
4242
},
4343
groups = {
44-
@Group(name = OperationsDb.DB, description = "Commands acting of database", commands = {
44+
@Group(name = OperationsDb.DB, description = "Manage databases", commands = {
4545
DbCreateCli.class,
4646
DbDeleteCli.class,
4747
DbListCli.class,
4848
DbShow.class
4949
}),
50-
@Group(name = "config", description = "Edit configuration file", commands = {
50+
@Group(name = "config", description = "Manage configuration file", commands = {
5151
ConfigCreate.class,
5252
ConfigDefault.class,
5353
ConfigDelete.class,
5454
ConfigShow.class,
5555
ConfigList.class
5656
}),
57-
@Group(name= "role", description = "Manage the roles (RBAC)", commands = {
57+
@Group(name= "role", description = "Manage roles (RBAC)", commands = {
5858
RoleListCli.class,
5959
RoleShowCli.class
6060
}),
61-
@Group(name= "user", description = "Manage the users permissions", commands = {
61+
@Group(name= "user", description = "Manage users", commands = {
6262
UserListCli.class,
6363
UserShowCli.class,
6464
UserInviteCli.class,
6565
UserDeleteCli.class
6666
}),
67-
@Group(name= "token", description = "Manage the security tokens", commands = {
68-
67+
/*
68+
@Group(name= "token", description = "Manage security tokens", commands = {
6969
}),
70-
@Group(name= "acl", description = "Manage the access lists", commands = {
71-
72-
})
73-
70+
@Group(name= "acl", description = "Manage Access lists", commands = {
71+
})*/
7472
})
7573
public class AstraCli {
7674

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.datastax.astra.shell.cmd.db.DbCreateShell;
77
import com.datastax.astra.shell.cmd.db.DbDeleteShell;
88
import com.datastax.astra.shell.cmd.db.DbListShell;
9+
import com.datastax.astra.shell.cmd.db.DbUseShell;
910
import com.datastax.astra.shell.cmd.db.OperationsDb;
1011
import com.datastax.astra.shell.cmd.iam.RoleListShell;
1112
import com.datastax.astra.shell.cmd.iam.RoleShowCli;
@@ -16,7 +17,6 @@
1617
import com.datastax.astra.shell.cmd.shell.ConnectCommand;
1718
import com.datastax.astra.shell.cmd.shell.CqlShCommand;
1819
import com.datastax.astra.shell.cmd.shell.EmptyCommand;
19-
import com.datastax.astra.shell.cmd.use.UseDb;
2020
import com.datastax.astra.shell.utils.LoggerShell;
2121
import com.github.rvesse.airline.annotations.Cli;
2222
import com.github.rvesse.airline.annotations.Group;
@@ -44,7 +44,8 @@
4444
@Group(name = OperationsDb.DB, description = "Commands acting of database", commands = {
4545
DbCreateShell.class,
4646
DbDeleteShell.class,
47-
DbListShell.class
47+
DbListShell.class,
48+
DbUseShell.class
4849
}),
4950
@Group(name= "role", description = "Manage the roles (RBAC)", commands = {
5051
RoleListShell.class,
@@ -55,10 +56,7 @@
5556
UserShowShell.class,
5657
UserInviteShell.class,
5758
UserDeleteShell.class
58-
}),
59-
@Group(name = "use", description = "Focus on an entity (context & prompt changed)", commands = {
60-
UseDb.class
61-
}),
59+
})
6260
})
6361
public class AstraShell {
6462

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public abstract class BaseCommand implements Runnable {
2222
/** Command constants. */
2323
public static final String LIST = "list";
2424

25+
/** Command constants. */
26+
public static final String USE = "use";
27+
2528
// --- Flags ---
2629

2730
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @param <T>
1212
*/
13-
@Command(name = "help", description = "Display help information")
13+
@Command(name = "help", description = "View help for any command")
1414
public class HelpCommand<T> extends Help<T> {
1515

1616
/** {@inheritDoc} */

astra-shell/src/main/java/com/datastax/astra/shell/cmd/config/Setup.java renamed to astra-shell/src/main/java/com/datastax/astra/shell/cmd/config/ConfigSetup.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
*
1818
* @author Cedrick LUNVEN (@clunven)
1919
*/
20-
@Command(
21-
name = "setup",
22-
description = "Intialize configuration")
23-
public class Setup extends BaseConfigCommand implements Runnable {
20+
@Command(name = "setup", description = "Initialize configuration file")
21+
public class ConfigSetup extends BaseConfigCommand implements Runnable {
2422

2523
/** {@inheritDoc} */
2624
@Override
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.datastax.astra.shell.cmd.db;
2+
3+
import java.util.Optional;
4+
5+
import com.datastax.astra.sdk.databases.DatabaseClient;
6+
import com.datastax.astra.shell.ExitCode;
7+
import com.datastax.astra.shell.cmd.BaseCommand;
8+
import com.datastax.astra.shell.cmd.BaseShellCommand;
9+
import com.datastax.astra.shell.utils.LoggerShell;
10+
import com.github.rvesse.airline.annotations.Arguments;
11+
import com.github.rvesse.airline.annotations.Command;
12+
import com.github.rvesse.airline.annotations.restrictions.Required;
13+
14+
/**
15+
* Select one Database in the Shell.
16+
*
17+
* @author Cedrick LUNVEN (@clunven)
18+
*/
19+
@Command(name = BaseCommand.USE, description = "Select a database in the shell")
20+
public class DbUseShell extends BaseShellCommand {
21+
22+
@Required
23+
@Arguments(title = "DB", description = "Database name or identifier")
24+
public String database;
25+
26+
/** {@inheritDoc} */
27+
@Override
28+
public ExitCode execute() {
29+
// We want the use command to be verbose
30+
this.verbose = true;
31+
Optional<DatabaseClient> dbClient = OperationsDb.getDatabaseClient(database);
32+
if (dbClient.isPresent()) {
33+
ctx().useDatabase(dbClient.get().find().get());
34+
LoggerShell.info("Selecting Database '" + database + "'");
35+
return ExitCode.SUCCESS;
36+
}
37+
return ExitCode.NOT_FOUND;
38+
}
39+
40+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Cedrick LUNVEN (@clunven)
1818
*/
19-
@Command(name = "shell", description = "Enter interactive mode")
19+
@Command(name = "shell", description = "Interactive mode (default if no command provided)")
2020
public class ShellCommand extends BaseCliCommand {
2121

2222
/**

astra-shell/src/main/java/com/datastax/astra/shell/cmd/use/UseDb.java

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

astra-shell/src/test/java/com/datastax/astra/RolesCommandsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class RolesCommandsTest extends AbstractAstraCliTest {
1212

1313
@Test
1414
public void interactive() throws Exception {
15-
astraCli( "--verbose");
15+
astraCli();
1616
}
1717

1818
@Test

0 commit comments

Comments
 (0)