-
Notifications
You must be signed in to change notification settings - Fork 1
/
ls.py
30 lines (25 loc) · 961 Bytes
/
ls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
""" Module that runs the ls command """
import os
import shutil
import textwrap
MAN_DOC = """ls - list files and directories
Usage: ls [directory]
Executing the command with no directory argument will list the files and folders in the current working directory.
Executing the command with a directory argument will list the files and folders in the directory specified."""
def run_command(options, arguments):
""" Function that runs the ls command """
return_code = 0
try:
dir_to_scan = arguments[0]
except:
dir_to_scan = '.'
file_dir_list = os.listdir(os.path.abspath(dir_to_scan))
terminal_width = int(shutil.get_terminal_size()[0])
constructed_string = ""
for thing in file_dir_list:
constructed_string += thing
constructed_string += ' \t\t\t'
done_first_thing = True
lines = textwrap.fill(text=constructed_string, width=terminal_width)
print(lines)
return return_code