Skip to content

Commit 14d3c4d

Browse files
authored
Merge pull request #99 from zedbeit/starfix-default-config
2 parents c27447d + a43eb4a commit 14d3c4d

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

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

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

5656
@Command(name = "clone")
5757
public int cloneCmd(@Parameters(index = "0") String url) {
58+
File configFilePath = getConfigFilePath(); // Get path for config file
59+
60+
if (!configFilePath.exists()) {// Check if config file exist
61+
defaultConfig(); // Sets up default config
62+
}
63+
5864
CloneUrl cloneUrl = new CloneUrl(url);
5965
// URL Validation to check a valid git repository
6066
if (!validate_url(cloneUrl.url)) { // Incase URI doesn't macth our scheme we'll terminate
@@ -116,25 +122,58 @@ public static boolean isBlob(String url){
116122
return Pattern.matches(pattern,url);
117123
}
118124

119-
// Function yo determine if the current OS is Windows
125+
// Function to determine if the current OS is Windows
120126
public static boolean isWindows() {
121127
return System.getProperty("os.name").toLowerCase().contains("windows");
122128
}
123129

130+
// Function to determine if the current OS is Linux
131+
public static boolean isLinux() {
132+
return System.getProperty("os.name").toLowerCase().contains("linux");
133+
}
134+
135+
// Function to determine if the current OS is MacOS
136+
public static boolean isMac() {
137+
return System.getProperty("os.name").toLowerCase().contains("mac");
138+
}
139+
140+
// Function to fetch config file path
141+
public static File getConfigFilePath(){
142+
String userHome = System.getProperty("user.home");
143+
return new File(userHome + "/.config/starfix.yaml");
144+
}
145+
124146
// Function to fetch config file
125147
public static File getConfigFile() {
126-
String userHome = System.getProperty("user.home"); // Get User Home Directory: /home/user_name
127-
File configDir = new File(userHome+ "/.config");
128-
129-
if(!configDir.exists()){ // If .config directory does not exist we create it
130-
if(!configDir.mkdirs()){ // If creation failed
131-
throw new IllegalStateException("Cannot create .config directory: " + configDir.getAbsolutePath());
148+
File configFilePath = getConfigFilePath();
149+
150+
if(!configFilePath.getParentFile().exists()){// Check if parent directory exists
151+
if(!configFilePath.getParentFile().mkdirs()){// Create parent dir if not exist
152+
throw new IllegalStateException("Cannot create .config directory: " + configFilePath.getParentFile().getAbsolutePath());
132153
}
133154
}
134-
return new File(userHome + "/.config/starfix.yaml");
155+
return configFilePath;
135156

136157
}
137-
158+
159+
// Function to setup default config
160+
void defaultConfig() {
161+
String path_env = System.getenv("Path"); // System PATH variable
162+
clone_path = System.getProperty("user.home") + "/code"; // set clone_path to /home/user_name/code
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+
} else if(path_env.contains("IntelliJ IDEA")){ // If PATH has IntelliJ
168+
ide = "idea64.exe";
169+
}
170+
}
171+
// check if Linux OS
172+
// if(isLinux()){}
173+
174+
// check if Mac OS
175+
// if(isMac()){}
176+
}
138177
// Function to edit configuration and serves for command line starfix config
139178
// editor
140179
public void editConfig() throws Exception {
@@ -146,6 +185,7 @@ public void editConfig() throws Exception {
146185
System.out.println("IDE: "+ide);
147186
System.out.println("Clone Path: "+clone_path);
148187

188+
// return a File
149189
File configFile = getConfigFile();
150190

151191
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

0 commit comments

Comments
 (0)