Skip to content

Commit 0027636

Browse files
committed
added -1 flag, used ruff format command
1 parent e3aafe0 commit 0027636

File tree

1 file changed

+23
-25
lines changed
  • implement-shell-tools/ls

1 file changed

+23
-25
lines changed

implement-shell-tools/ls/ls.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
import time
77

88
parser = argparse.ArgumentParser(
9-
prog = "ls-command",
10-
description= "ls shell command on python"
9+
prog="ls-command", description="ls shell command on python"
1110
)
1211

13-
parser.add_argument("-l", action="store_true", help="Display long format description files")
14-
parser.add_argument("-a", action="store_true", help="Display hidden files along with visible")
12+
parser.add_argument("-1", action="store_true", dest="one", help="One file per line")
13+
parser.add_argument(
14+
"-l", action="store_true", help="Display long format description files"
15+
)
16+
parser.add_argument(
17+
"-a", action="store_true", help="Display hidden files along with visible"
18+
)
1519
parser.add_argument("path", nargs="*", default=["."], help="The file to search")
1620

17-
args=parser.parse_args()
21+
22+
args = parser.parse_args()
23+
1824

1925
def long_format(path, file):
2026
info = os.stat(path)
@@ -23,8 +29,7 @@ def long_format(path, file):
2329
owner = pwd.getpwuid(info.st_uid).pw_name
2430
group = grp.getgrgid(info.st_gid).gr_name
2531
mtime = time.strftime("%b %d %H:%M", time.localtime(info.st_mtime))
26-
print (permissions, size_file, owner, group, mtime, file)
27-
32+
print(permissions, size_file, owner, group, mtime, file)
2833

2934

3035
for path in args.path:
@@ -37,23 +42,16 @@ def long_format(path, file):
3742
elif os.path.isdir(path):
3843
files = os.listdir(path)
3944

40-
if not args.a:
41-
visible_files=[]
42-
for file in files:
43-
if not file.startswith("."):
44-
visible_files.append(file)
45-
files=visible_files
46-
47-
for file in files:
48-
full_file_path = os.path.join(path, file)
49-
50-
if args.l:
51-
long_format(full_file_path, file)
52-
else:
53-
print(file)
54-
55-
56-
57-
45+
if not args.a:
46+
files = [file for file in files if not file.startswith(".")]
5847

48+
for file in files:
49+
full_file_path = os.path.join(path, file)
5950

51+
if args.l:
52+
long_format(full_file_path, file)
53+
else:
54+
if args.one:
55+
print(file)
56+
else:
57+
print(file, "\n")

0 commit comments

Comments
 (0)