Skip to content

Commit e073891

Browse files
committed
made changes to getconfigfile
1 parent 4438ac4 commit e073891

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

cli/src/main/java/dev/starfix/Starfix.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public int config() throws Exception {
5555

5656
@Command(name = "clone")
5757
public int cloneCmd(@Parameters(index = "0") String url) {
58-
File configFile = getConfigFile();
58+
File configFilePath = getConfigFilePath(); // Get path for config file
5959

6060
try {
61-
if (!configFile.exists()) {
61+
if (!configFilePath.exists()) {// Check if config file exist
6262
defaultConfig();
6363
}
6464
} catch (Exception e) {
@@ -142,19 +142,25 @@ public static boolean isMac() {
142142
return System.getProperty("os.name").toLowerCase().contains("mac");
143143
}
144144

145+
// Function to fetch config file path
146+
public static File getConfigFilePath(){
147+
String userHome = System.getProperty("user.home");
148+
return new File(userHome + "/.config/starfix.yaml");
149+
}
150+
145151
// Function to fetch config file
146152
public static File getConfigFile() {
147-
String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name
148-
File configDir = new File(userHome+ "/.config");
149-
150-
if(!configDir.exists()){ // If .config directory does not exist we create it
151-
if(!configDir.mkdirs()){ // If creation failed
152-
throw new IllegalStateException("Cannot create .config directory: " + configDir.getAbsolutePath());
153+
File configFilePath = getConfigFilePath();
154+
155+
if(!configFilePath.getParentFile().exists()){// Check if parent directory exists
156+
if(!configFilePath.getParentFile().mkdirs()){// Create parent dir if not exist
157+
throw new IllegalStateException("Cannot create .config directory: " + configFilePath.getParentFile().getAbsolutePath());
153158
}
154159
}
155-
return new File(userHome + "/.config/starfix.yaml");
160+
return configFilePath;
156161

157162
}
163+
158164
// Function to load default config
159165
public void defaultConfig() {
160166
String path_env = System.getenv("Path"); // System PATH variable

0 commit comments

Comments
 (0)