File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/python3
2+
3+ import os
4+ from optparse import OptionParser
5+
6+
7+ def dirname (opts , names : list [str ]):
8+ for name in names :
9+ print (os .path .dirname (name ) or "." , end = "\0 " if opts .zero else "\n " )
10+
11+
12+ if __name__ == "__main__" :
13+ parser = OptionParser (
14+ usage = "Usage: %prog [OPTION]... NAME..." ,
15+ description = (
16+ "Print each path NAME with the last component removed,"
17+ " or '.' if NAME is the only component."
18+ ),
19+ add_help_option = False ,
20+ )
21+ parser .add_option ("--help" , action = "help" , help = "show usage information and exit" )
22+
23+ parser .add_option (
24+ "-z" ,
25+ "--zero" ,
26+ action = "store_true" ,
27+ help = "terminate outputs with NUL instead of newline" ,
28+ )
29+
30+ opts , args = parser .parse_args ()
31+
32+ if not args :
33+ parser .error ("missing operand" )
34+
35+ dirname (opts , args )
You can’t perform that action at this time.
0 commit comments