Skip to content

Commit fa0fbd2

Browse files
committed
Refactoring to ouput json, csv
1 parent d0c0331 commit fa0fbd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1408
-775
lines changed

astra-sdk/src/main/java/com/datastax/astra/sdk/utils/AstraRc.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class AstraRc {
5757
* Load from ~/.astrarc
5858
*/
5959
public AstraRc() {
60-
this(System.getProperty(ENV_USER_HOME) + File.separator + ASTRARC_FILENAME);
60+
this(getDefaultConfigurationFileName());
6161
}
6262

6363
/**
@@ -81,7 +81,17 @@ public AstraRc(String fileName) {
8181
* if default config exists
8282
*/
8383
public static boolean isDefaultConfigFileExists() {
84-
return new File(System.getProperty(ENV_USER_HOME) + File.separator + ASTRARC_FILENAME).exists();
84+
return new File(getDefaultConfigurationFileName()).exists();
85+
}
86+
87+
/**
88+
* Build default configuration filename.
89+
*
90+
* @return
91+
* default configuration file name
92+
*/
93+
public static String getDefaultConfigurationFileName() {
94+
return System.getProperty(ENV_USER_HOME) + File.separator + ASTRARC_FILENAME;
8595
}
8696

8797
/**
@@ -315,6 +325,16 @@ public void createSectionWithToken(String sectionName, String token) {
315325
if (!isSectionExists(ASTRARC_DEFAULT)) {
316326
copySection(sectionName, ASTRARC_DEFAULT);
317327
}
328+
}
329+
330+
/**
331+
* Getter accessor for attribute 'configFile'.
332+
*
333+
* @return
334+
* current value of 'configFile'
335+
*/
336+
public File getConfigFile() {
337+
return configFile;
318338
}
319339

320340
}

astra-shell/dependency-reduced-pom.xml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<plugin>
9292
<groupId>org.graalvm.buildtools</groupId>
9393
<artifactId>native-maven-plugin</artifactId>
94-
<version>0.9.11</version>
94+
<version>${native.maven.plugin.version}</version>
9595
<extensions>true</extensions>
9696
<executions>
9797
<execution>
@@ -100,25 +100,6 @@
100100
<goals>
101101
<goal>build</goal>
102102
</goals>
103-
<configuration>
104-
<imageName>astra-native</imageName>
105-
<useArgFile>false</useArgFile>
106-
<quickBuild>false</quickBuild>
107-
<skipNativeBuild>false</skipNativeBuild>
108-
<mainClass>com.datastax.astra.shell.AstraCli</mainClass>
109-
<fallback>false</fallback>
110-
<verbose>true</verbose>
111-
<buildArgs>
112-
<buildArg>-H:+ReportExceptionStackTraces</buildArg>
113-
<buildArg>-H:EnableURLProtocols=http,https</buildArg>
114-
<buildArg>--allow-incomplete-classpath</buildArg>
115-
<buildArg>--report-unsupported-elements-at-runtime</buildArg>
116-
<buildArg>--verbose</buildArg>
117-
</buildArgs>
118-
<classpath>
119-
<param>/Users/cedricklunven/dev/workspaces/datastax/astra-sdk-java/astra-shell/target/astra-shell-0.3.2-SNAPSHOT-shaded.jar</param>
120-
</classpath>
121-
</configuration>
122103
</execution>
123104
</executions>
124105
<configuration>
@@ -137,7 +118,7 @@
137118
<buildArg>--verbose</buildArg>
138119
</buildArgs>
139120
<classpath>
140-
<param>/Users/cedricklunven/dev/workspaces/datastax/astra-sdk-java/astra-shell/target/astra-shell-0.3.2-SNAPSHOT-shaded.jar</param>
121+
<param>${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar</param>
141122
</classpath>
142123
</configuration>
143124
</plugin>

astra-shell/pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
<version>${jansi.version}</version>
3838
</dependency>
3939
<dependency>
40-
<groupId>org.slf4j</groupId>
41-
<artifactId>slf4j-jdk14</artifactId>
42-
<version>1.7.25</version>
43-
</dependency>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-nop</artifactId>
42+
</dependency>
4443

4544
<!-- Leveraging SDK for Astra Accesses -->
4645
<dependency>

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

Lines changed: 25 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@
33
import org.fusesource.jansi.AnsiConsole;
44

55
import com.datastax.astra.shell.cmd.HelpCommand;
6-
import com.datastax.astra.shell.cmd.config.ConfigCreateCommand;
7-
import com.datastax.astra.shell.cmd.config.ConfigDefaultCommand;
8-
import com.datastax.astra.shell.cmd.config.ConfigDeleteCommand;
9-
import com.datastax.astra.shell.cmd.config.ConfigListCommand;
10-
import com.datastax.astra.shell.cmd.config.ConfigShowCommand;
11-
import com.datastax.astra.shell.cmd.config.SetupCommand;
12-
import com.datastax.astra.shell.cmd.db.CreateDatabaseCommand;
13-
import com.datastax.astra.shell.cmd.db.DatabaseCommandUtils;
14-
import com.datastax.astra.shell.cmd.db.CreateDatabaseCommand.CreateDatabaseCommandAlias1;
15-
import com.datastax.astra.shell.cmd.db.DeleteDatabaseCommand;
16-
import com.datastax.astra.shell.cmd.db.DeleteDatabaseCommand.DeleteDatabaseCommandAlias1;
17-
import com.datastax.astra.shell.cmd.db.ShowDatabaseCommand;
18-
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand;
19-
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand.ShowDatabasesCommandBis;
20-
import com.datastax.astra.shell.cmd.iam.ShowRoleCommand;
21-
import com.datastax.astra.shell.cmd.iam.ShowRolesCommand;
22-
import com.datastax.astra.shell.cmd.iam.ShowUserCommand;
23-
import com.datastax.astra.shell.cmd.iam.ShowUsersCommands;
6+
import com.datastax.astra.shell.cmd.config.ConfigCreate;
7+
import com.datastax.astra.shell.cmd.config.ConfigDefault;
8+
import com.datastax.astra.shell.cmd.config.ConfigDelete;
9+
import com.datastax.astra.shell.cmd.config.ConfigList;
10+
import com.datastax.astra.shell.cmd.config.ConfigShow;
11+
import com.datastax.astra.shell.cmd.config.Setup;
12+
import com.datastax.astra.shell.cmd.db.Db;
13+
import com.datastax.astra.shell.cmd.db.DbCreateCli;
14+
import com.datastax.astra.shell.cmd.db.DbDelete;
15+
import com.datastax.astra.shell.cmd.db.DbListCli;
2416
import com.datastax.astra.shell.cmd.shell.ShellCommand;
25-
import com.datastax.astra.shell.cmd.show.ShowConfigCommand;
26-
import com.datastax.astra.shell.cmd.show.ShowConfigsCommand;
2717
import com.datastax.astra.shell.utils.LoggerShell;
2818
import com.github.rvesse.airline.annotations.Cli;
2919
import com.github.rvesse.airline.annotations.Group;
@@ -39,78 +29,22 @@
3929
description = "CLI for DataStax Astra™ including an interactive mode",
4030
defaultCommand = ShellCommand.class, // no command => interactive
4131
commands = {
42-
SetupCommand.class,
32+
Setup.class,
4333
HelpCommand.class,
4434
ShellCommand.class
4535
},
4636
groups = {
47-
@Group(
48-
name = "show", description = "Display entity details or list entities",
49-
commands = {
50-
// List Db in the organization (dbs | databases)
51-
ShowDatabasesCommand.class,
52-
ShowDatabasesCommandBis.class,
53-
// List Roles in the current organization/tenant
54-
ShowRolesCommand.class,
55-
// Display details of a role (permissions)
56-
ShowRoleCommand.class,
57-
// Display details of a user (roles, permissions, metadata)
58-
ShowUserCommand.class,
59-
// List Users in the current organization/tenant
60-
ShowUsersCommands.class,
61-
// Show current configuration
62-
ShowConfigsCommand.class,
63-
ShowConfigCommand.class
64-
}
65-
),
66-
@Group(
67-
name = "list", description = "Display list of entities",
68-
commands = {
69-
// List Db in the organization (dbs | databases)
70-
ShowDatabaseCommand.class,
71-
ShowDatabasesCommand.class,
72-
ShowDatabasesCommandBis.class,
73-
ShowRolesCommand.class,
74-
ShowUsersCommands.class,
75-
ShowConfigsCommand.class,
76-
ShowConfigCommand.class
77-
}
78-
),
79-
@Group(
80-
name = "config",
81-
description = "Edit configuration file",
82-
commands = {
83-
ConfigCreateCommand.class,
84-
ConfigDefaultCommand.class,
85-
ConfigDeleteCommand.class,
86-
ConfigShowCommand.class,
87-
ConfigListCommand.class
88-
}
89-
),
90-
@Group(
91-
name = "create",
92-
description = "Create entities (db, tenant, user, role...)",
93-
commands = {
94-
CreateDatabaseCommand.class,
95-
CreateDatabaseCommandAlias1.class
96-
}
97-
),
98-
@Group(
99-
name = "delete",
100-
description = "Delete existing entities (db, tenant, user, role...)",
101-
commands = {
102-
DeleteDatabaseCommand.class,
103-
DeleteDatabaseCommandAlias1.class,
104-
}
105-
),
106-
// Noun then verb
107-
@Group(
108-
name = DatabaseCommandUtils.DB,
109-
description = "Commands at Database level",
110-
commands = {
111-
CreateDatabaseCommand.class,
112-
CreateDatabaseCommandAlias1.class
113-
}
37+
@Group(name = Db.DB, description = "Commands acting of database", commands = {
38+
DbCreateCli.class,
39+
DbListCli.class
40+
}),
41+
@Group(name = "config", description = "Edit configuration file", commands = {
42+
ConfigCreate.class,
43+
ConfigDefault.class,
44+
ConfigDelete.class,
45+
ConfigShow.class,
46+
ConfigList.class
47+
}
11448
),
11549
})
11650
public class AstraCli {
@@ -135,10 +69,10 @@ public static void main(String[] args) {
13569

13670
} catch(ParseArgumentsUnexpectedException ex) {
13771
LoggerShell.error("Invalid command: " + ex.getMessage());
138-
ex.printStackTrace();
72+
//ex.printStackTrace();
13973
} catch(Exception e) {
14074
LoggerShell.error("Execution error:" + e.getMessage());
141-
e.printStackTrace();
75+
//e.printStackTrace();
14276
}
14377
}
14478

@@ -152,4 +86,5 @@ public static void exec(String ...args) {
15286
main(args);
15387
}
15488

89+
15590
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import com.datastax.astra.shell.cmd.ExitCommand;
44
import com.datastax.astra.shell.cmd.HelpCommand;
55
import com.datastax.astra.shell.cmd.QuitCommand;
6-
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand;
7-
import com.datastax.astra.shell.cmd.db.ShowDatabasesCommand.ShowDatabasesCommandBis;
8-
import com.datastax.astra.shell.cmd.db.UseDatabaseCommand;
6+
import com.datastax.astra.shell.cmd.db.DbListShell;
97
import com.datastax.astra.shell.cmd.iam.ShowRoleCommand;
108
import com.datastax.astra.shell.cmd.iam.ShowRolesCommand;
119
import com.datastax.astra.shell.cmd.iam.ShowUserCommand;
@@ -14,6 +12,7 @@
1412
import com.datastax.astra.shell.cmd.shell.CqlShCommand;
1513
import com.datastax.astra.shell.cmd.shell.EmptyCommand;
1614
import com.datastax.astra.shell.cmd.show.ShowConfigsCommand;
15+
import com.datastax.astra.shell.cmd.use.UseDb;
1716
import com.datastax.astra.shell.utils.LoggerShell;
1817
import com.github.rvesse.airline.annotations.Cli;
1918
import com.github.rvesse.airline.annotations.Group;
@@ -42,7 +41,7 @@
4241
name = "show",
4342
description = "Listing details of an entity or entity list",
4443
commands = {
45-
ShowDatabasesCommand.class, ShowDatabasesCommandBis.class,
44+
DbListShell.class,
4645
ShowRoleCommand.class, ShowRolesCommand.class,
4746
ShowUserCommand.class, ShowUsersCommands.class,
4847
ShowConfigsCommand.class }
@@ -51,7 +50,7 @@
5150
name = "use",
5251
description = "Focus on an entity (context & prompt changed)",
5352
commands = {
54-
UseDatabaseCommand.class
53+
UseDb.class
5554
}
5655
)
5756
})

0 commit comments

Comments
 (0)