11package com .datastax .cdm ;
22
3+ import com .beust .jcommander .JCommander ;
34import com .datastax .driver .core .*;
45import com .fasterxml .jackson .core .type .TypeReference ;
56import com .fasterxml .jackson .databind .ObjectMapper ;
1617import org .eclipse .jgit .api .errors .TransportException ;
1718import org .eclipse .jgit .events .ListenerHandle ;
1819
20+ import com .beust .jcommander .Parameter ;
21+
22+
1923
2024import java .lang .StringBuilder ;
2125
@@ -36,23 +40,32 @@ public class CassandraDatasetManager {
3640 public class InvalidArgsException extends Exception {
3741
3842 }
43+
44+
3945 private static final String YAML_URI = "https://raw.githubusercontent.com/riptano/cdm-java/master/datasets.yaml" ;
4046 private Map <String , Dataset > datasets ;
4147 private Session session ;
4248 private String cassandraContactPoint ;
49+ private String host ;
4350
44- CassandraDatasetManager () {
4551
52+
53+ CassandraDatasetManager () {
54+ this .host = "localhost" ;
4655 }
4756
48- CassandraDatasetManager (Map <String , Dataset > datasets ) {
57+ CassandraDatasetManager (String host , Map <String , Dataset > datasets ) {
4958 this .datasets = datasets ;
59+ this .host = host ;
5060 }
5161
5262
5363 public static void main (String [] args ) throws IOException , ParseException , InterruptedException , GitAPIException {
5464
5565 System .out .println ("Starting CDM" );
66+ CDMArgs parsedArgs = new CDMArgs ();
67+ new JCommander (parsedArgs , args );
68+
5669
5770 // check for the .cdm directory
5871 String home_dir = System .getProperty ("user.home" );
@@ -75,13 +88,7 @@ public static void main(String[] args) throws IOException, ParseException, Inter
7588 Map <String , Dataset > data = mapper .readValue (yaml , new TypeReference <Map <String , Dataset >>() {} );
7689
7790 // debug: show all datasets no matter what
78- CassandraDatasetManager cdm = new CassandraDatasetManager (data );
79-
80- // parse the CLI options
81- Options options = new Options ();
82-
83- CommandLineParser parser = new DefaultParser ();
84- CommandLine cmd = parser .parse (options , args );
91+ CassandraDatasetManager cdm = new CassandraDatasetManager (parsedArgs .host , data );
8592
8693 // create a cluster and session
8794
@@ -94,15 +101,15 @@ public static void main(String[] args) throws IOException, ParseException, Inter
94101 }
95102
96103 // connect to the cluster via the driver
97- switch (args [ 0 ] ) {
104+ switch (parsedArgs . command . get ( 0 ) ) {
98105 case "install" :
99- cdm .install (args [ 1 ] );
106+ cdm .install (parsedArgs . command . get ( 1 ) );
100107 break ;
101108 case "list" :
102109 cdm .list ();
103110 break ;
104111 case "new" :
105- cdm .new_dataset (args [ 1 ] );
112+ cdm .new_dataset (parsedArgs . command . get ( 1 ) );
106113 break ;
107114 case "dump" :
108115 cdm .dump ();
@@ -223,7 +230,7 @@ void install(String name) throws IOException, InterruptedException, GitAPIExcept
223230 ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
224231
225232 Config config = mapper .readValue (configFile , Config .class );
226- String address = "127.0.0.1" ;
233+ String address = this . host ;
227234 {
228235 Cluster cluster = Cluster .builder ().addContactPoint (address ).build ();
229236 Session session = cluster .connect ();
0 commit comments