Skip to content

Commit 3617742

Browse files
committed
set up parser
1 parent 9361dde commit 3617742

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • implement-shell-tools/ls

‎implement-shell-tools/ls/ls.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import argparse
2+
import sys
3+
4+
parser = argparse.ArgumentParser(
5+
prog="a simple version of ls",
6+
description="ls command line tool which can accept 0 or more arguements" \
7+
"and take -a and -1 flags")
8+
9+
parser.add_argument("-a", action="store_true", help="show all files, including dot files")
10+
11+
# can't store as an attribute of Namespace object, because 1 is not a valid python identifier
12+
# but can store under the name given in the dest argument. When working with this
13+
# parser, look for "opt_one", not "1".
14+
parser.add_argument("-1", dest="opt_one", action="store_true", help="show one file/directory name per line")
15+
16+
# takes 0 more arguments, if none are given, sets "." as default value
17+
parser.add_argument("paths", nargs="*", help="file/directory path(s) to display", default=".")
18+
19+
args = parser.parse_args()
20+
21+
print(args)
22+
23+
# def getDirectoryEntries(path, aFlag=args.a):

0 commit comments

Comments
 (0)