@@ -55,6 +55,14 @@ public int config() throws Exception {
5555
5656 @ Command (name = "clone" )
5757 public int cloneCmd (@ Parameters (index = "0" ) String url ) {
58+ String userHome = System .getProperty ("user.home" ); // Get User Home Directory: /home/user_name
59+ Path configPath = Paths .get (userHome + "/.config/starfix.yaml" );
60+
61+ //Check if config file does not exist
62+ if (!Files .exists (configPath )){
63+ defaultConfig ();
64+ }
65+
5866 CloneUrl cloneUrl = new CloneUrl (url );
5967 // URL Validation to check a valid git repository
6068 if (!validate_url (cloneUrl .url )) { // Incase URI doesn't macth our scheme we'll terminate
@@ -116,11 +124,21 @@ public static boolean isBlob(String url){
116124 return Pattern .matches (pattern ,url );
117125 }
118126
119- // Function yo determine if the current OS is Windows
127+ // Function to determine if the current OS is Windows
120128 public static boolean isWindows () {
121129 return System .getProperty ("os.name" ).toLowerCase ().contains ("windows" );
122130 }
123131
132+ // Function to determine if the current OS is Linux
133+ public static boolean isLinux () {
134+ return System .getProperty ("os.name" ).toLowerCase ().contains ("linux" );
135+ }
136+
137+ // Function to determine if the current OS is MacOS
138+ public static boolean isMac () {
139+ return System .getProperty ("os.name" ).toLowerCase ().contains ("mac" );
140+ }
141+
124142 // Function to fetch config file
125143 public static File getConfigFile () {
126144 String userHome = System .getProperty ("user.home" ); // Get User Home Directory: /home/user_name
@@ -134,6 +152,44 @@ public static File getConfigFile() {
134152 return new File (userHome + "/.config/starfix.yaml" );
135153
136154 }
155+ // Function to load default config
156+ public void defaultConfig () {
157+ String path_env = System .getenv ("Path" ); // System PATH variable
158+ clone_path = System .getProperty ("user.home" ) + "/code" ; // set clone_path to /home/user_name/code
159+ File configFile = getConfigFile ();
160+
161+ try {
162+ configFile .createNewFile ();
163+
164+ if (isWindows ()){// check if Windows OS
165+ if (path_env .contains ("Microsoft VS Code" )){ // If PATH has VScode
166+ ide = "code.cmd" ;
167+ writeToYAMLFile (ide , clone_path ,configFile );
168+ } else if (path_env .contains ("IntelliJ IDEA" )){ // If PATH has IntelliJ
169+ ide = "idea64.exe" ;
170+ writeToYAMLFile (ide , clone_path ,configFile );
171+ }
172+ }
173+ // check if Linux OS
174+ // if(isLinux()){}
175+
176+ // check if Mac OS
177+ // if(isMac()){}
178+
179+ } catch (Exception e ) {
180+ e .printStackTrace ();
181+
182+ }
183+ }
184+ // Function to write configurations to the YAML FILE
185+ public void writeToYAMLFile (String ide , String clone_path , File configFile ) throws Exception {
186+ ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
187+ Properties configuration = new Properties ();
188+
189+ configuration .put ("ide" , ide );
190+ configuration .put ("clone_path" ,clone_path );
191+ mapper .writeValue (configFile , configuration );
192+ }
137193
138194 // Function to edit configuration and serves for command line starfix config
139195 // editor
@@ -146,6 +202,7 @@ public void editConfig() throws Exception {
146202 System .out .println ("IDE: " +ide );
147203 System .out .println ("Clone Path: " +clone_path );
148204
205+ // return a File
149206 File configFile = getConfigFile ();
150207
151208 BufferedReader reader = new BufferedReader (new InputStreamReader (System .in ));
0 commit comments