Skip to content

Commit e415ef3

Browse files
Merge pull request #32 from nihaltp/feat/tree
Feat/tree and update checklist
2 parents 705d472 + 09af437 commit e415ef3

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

CheckList.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 🧭 System Information & Management
1010
- [ ] systeminfo
11-
- [ ] hostname
11+
- [x] hostname
1212
- [x] ver
1313
- [ ] vol
1414
- [ ] set
@@ -38,7 +38,7 @@
3838
- [x] move
3939
- [ ] rename / ren
4040
- [ ] attrib
41-
- [ ] tree
41+
- [x] tree
4242
- [x] type
4343
- [ ] more
4444
- [ ] find
@@ -97,7 +97,7 @@
9797
- [ ] net user
9898
- [ ] net localgroup
9999
- [ ] runas
100-
- [ ] whoami
100+
- [x] whoami
101101
- [ ] cacls
102102
- [ ] icacls
103103
- [ ] cipher
@@ -111,9 +111,9 @@
111111
- [ ] pause
112112
- [x] cls
113113
- [x] exit
114-
- [ ] title
115-
- [ ] color
116-
- [ ] time
114+
- [x] title
115+
- [x] color
116+
- [x] time
117117
- [x] date
118118
- [ ] shutdown
119119
- [ ] choice
@@ -172,7 +172,7 @@
172172
- [ ] call
173173
- [x] cd / chdir
174174
- [x] cls
175-
- [ ] color
175+
- [x] color
176176
- [x] copy
177177
- [x] date
178178
- [x] del / erase
@@ -200,8 +200,8 @@
200200
- [ ] setlocal
201201
- [ ] shift
202202
- [ ] start
203-
- [ ] time
204-
- [ ] title
203+
- [x] time
204+
- [x] title
205205
- [x] type
206206
- [x] ver
207207
- [ ] verify

src/main/java/com/mycmd/App.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private static void registerCommands(Map<String, Command> commands) {
5757
commands.put("whoami", new WhoamiCommand());
5858
commands.put("touch", new TouchCommand());
5959
commands.put("time", new TimeCommand());
60+
commands.put("tree", new TreeCommand());
6061
commands.put("date", new DateCommand());
6162
}
6263
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
import java.io.File;
6+
7+
public class TreeCommand implements Command {
8+
public void execute(String[] args, ShellContext context) {
9+
File[] files = context.getCurrentDir().listFiles();
10+
11+
if (files == null || files.length == 0) {
12+
System.out.println("No files found.");
13+
return;
14+
}
15+
16+
System.out.println(context.getCurrentDir().getAbsolutePath());
17+
printDirectory(files, "", true);
18+
System.out.println();
19+
}
20+
21+
private void printDirectory(File[] files, String prefix, boolean isLast) {
22+
if (files == null || files.length == 0) return;
23+
24+
for (int i = 0; i < files.length; i++) {
25+
File f = files[i];
26+
if (f.isHidden()) continue;
27+
28+
boolean last = (i == files.length - 1);
29+
System.out.println(prefix + (last ? "└───" : "├───") + f.getName());
30+
31+
if (f.isDirectory()) {
32+
String newPrefix = prefix + (last ? " " : "│ ");
33+
printDirectory(f.listFiles(), newPrefix, last);
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)