Skip to content

Commit 53a9aa9

Browse files
committed
Add support for -1 (single column) flag to ls implementation
1 parent fded319 commit 53a9aa9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

implement-shell-tools/ls/my_ls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
parser.add_argument("-l", "--longList", action="store_true", help="Long listing format")
1111
parser.add_argument("-a", "--all", action="store_true", help="Include hidden files")
1212

13+
parser.add_argument("-1", "--singleColumn", action="store_true", help="List one file per line")
1314
args = parser.parse_args()
1415

1516
file_paths = args.paths
1617
show_long = args.longList
1718
show_all = args.all
19+
force_single_column = args.singleColumn
1820

1921
def format_permissions(mode):
2022
return stat.filemode(mode)
@@ -38,6 +40,9 @@ def format_permissions(mode):
3840
if not show_all:
3941
entries = [e for e in entries if not e.startswith(".")]
4042

43+
# Optional: sort entries for consistent output
44+
entries.sort() # (optional for predictable output)
45+
4146
for entry in entries:
4247
full_path = os.path.join(input_path, entry)
4348
entry_stat = os.stat(full_path)
@@ -46,7 +51,7 @@ def format_permissions(mode):
4651
size = str(entry_stat.st_size).rjust(6)
4752
print(f"{perms} {size} {entry}")
4853
else:
49-
print(entry)
54+
print(entry)
5055

5156
except Exception as e:
5257
print(f'Error reading "{input_path}": {e}', file=sys.stderr)

0 commit comments

Comments
 (0)