Skip to content

Commit c3a9c0b

Browse files
committed
created new tool: fold
1 parent e503952 commit c3a9c0b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

darkbox/commands/fold.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
""" darkbox fold command """
2+
3+
from .template import Command
4+
5+
6+
class fold(Command):
7+
def __init__(self):
8+
self.version = '0.0.1'
9+
10+
def get_parser(self):
11+
parser = super().get_parser()
12+
parser.add_argument('-w', '--width', type=int, default=80, help='use WIDTH columns instead of 80')
13+
parser.add_argument('files', nargs='+')
14+
return parser
15+
16+
def run(self, args=None):
17+
args = self.get_args(args)
18+
19+
for i in args['files']:
20+
try:
21+
with open(i, 'r') as f:
22+
for line in f:
23+
# dear god solve this. its awful. but functional.
24+
for part in [line.rstrip('\n')[n:n+args['width']] for n in range(0, len(line), args['width'])]:
25+
print(part)
26+
27+
28+
except FileNotFoundError:
29+
self.file_not_found_error(i)
30+
31+
except IsADirectoryError:
32+
self.directory_error(i)

0 commit comments

Comments
 (0)