Skip to content

Commit ad5c2a8

Browse files
committed
Add file (optional argument) and --contents CLI args
1 parent aeff906 commit ad5c2a8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

editor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import print_function
22

3+
import locale
34
import os.path
45
import subprocess
56
import tempfile
@@ -74,8 +75,13 @@ def edit(filename=None, contents=None):
7475
def _get_editor(ns):
7576
print(get_editor())
7677

78+
7779
def _edit(ns):
78-
print(edit())
80+
contents = ns.contents
81+
if contents is not None:
82+
contents = contents.encode(locale.getpreferredencoding())
83+
print(edit(filename=ns.path, contents=contents))
84+
7985

8086
if __name__ == '__main__':
8187
import argparse
@@ -87,6 +93,8 @@ def _edit(ns):
8793

8894
cmd = sp.add_parser('edit')
8995
cmd.set_defaults(cmd=_edit)
96+
cmd.add_argument('path', type=str, nargs='?')
97+
cmd.add_argument('--contents', type=str)
9098

9199
ns = ap.parse_args()
92100
ns.cmd(ns)

0 commit comments

Comments
 (0)