Skip to content

Commit 3b6d430

Browse files
Remove commented-out code and clean up the 'ls' command implementation
1 parent e69ae43 commit 3b6d430

File tree

1 file changed

+1
-93
lines changed
  • implement-shell-tools/ls

1 file changed

+1
-93
lines changed

implement-shell-tools/ls/ls.py

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -44,96 +44,4 @@
4444
print(entry)
4545
else:
4646
print(" ".join(entries))
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
# .argument("[directory]", "The directory to list")
59-
# // Commander stores -1 as a string key that is accessed using options['1']
60-
# .option("-1", "List all files, one per line")
61-
# .option("-a, --all", "Include hidden files (those starting with .) in the listing")
62-
# .action(async (directory, options) => {
63-
# try {
64-
# // default to current directory if none is specified
65-
# const dir = directory || ".";
66-
67-
# await newLs(dir, options['1'], options.all);
68-
# } catch (err) {
69-
# console.error(`Error: ${err.message}`);
70-
# }
71-
# });
72-
73-
# program.parse(process.argv);
74-
75-
76-
# // filter files based on visibility (includeHidden = true includes all files)
77-
# function filterFiles(entries, includeHidden) {
78-
# return entries.filter(name =>
79-
# includeHidden ? true : !name.startsWith(".")
80-
# );
81-
# }
82-
83-
# // sort entries: directories first, then files,
84-
# function sortEntries(entries) {
85-
# const dirs = entries.filter(entry => {
86-
# try {
87-
# return fs.statSync(entry).isDirectory();
88-
# } catch (err) {
89-
# return false;
90-
# }
91-
# });
92-
93-
# const files = entries.filter(entry => {
94-
# try {
95-
# return fs.statSync(entry).isFile();
96-
# } catch (err) {
97-
# return false;
98-
# }
99-
# });
100-
# // localeCompare = take into account rules of system language/region for ordering
101-
# // undefined = uses the system default, numeric = regular number sorting, base = ignore case & accents
102-
# return entries.sort((a, b) =>
103-
# a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
104-
# );
105-
# }
106-
107-
108-
# // print entries either one per line (-1 flag)
109-
# function printEntries(entries) {
110-
# entries.forEach(entry => console.log(entry));
111-
# }
112-
113-
114-
# async function newLs(directory, oneFlag, allFlag) {
115-
# try {
116-
# // check if path exists and determine if file or directory
117-
# const stats = await fs.stat(directory);
118-
119-
# // if a file, just print the name
120-
# if (stats.isFile()) {
121-
# console.log(directory);
122-
# return;
123-
# }
124-
125-
# // reads directory contents
126-
# const entries = await fs.readdir(directory);
127-
128-
# // Filter out hidden files if no -a flag
129-
# const filteredEntries = filterFiles(entries, allFlag);
130-
131-
# // Sort the entries using the sortEntries helper
132-
# const sortedEntries = sortEntries(filteredEntries);
133-
134-
# // print entries for -1 flag (one per line)
135-
# printEntries(sortedEntries);
136-
# } catch (err) {
137-
# console.error(`ls: cannot access '${directory}': ${err.message}`);
138-
# }
139-
# }
47+

0 commit comments

Comments
 (0)