added replay to history command

This commit is contained in:
Anthony Scopatz 2015-08-26 22:29:28 -04:00
parent eb980e8c2f
commit a0c7ea9d03
2 changed files with 22 additions and 9 deletions

View file

@ -304,6 +304,12 @@ def _create_parser():
# diff
diff = subp.add_parser('diff', help='diffs two xonsh history files')
diff_history._create_parser(p=diff)
# replay, dynamically
from xonsh import replay
rp = subp.add_parser('replay', help='replays a xonsh history file')
replay._create_parser(p=rp)
_MAIN_ACTIONS['replay'] = replay._main_action
# set and return
_HIST_PARSER = p
return p

View file

@ -77,12 +77,14 @@ class Replayer(object):
_REPLAY_PARSER = None
def _create_parser():
def _create_parser(p=None):
global _REPLAY_PARSER
if _REPLAY_PARSER is not None:
p_was_none = (p is None)
if _REPLAY_PARSER is not None and p_was_none:
return _REPLAY_PARSER
from argparse import ArgumentParser
p = ArgumentParser('replay', description='replays a xonsh history file')
if p_was_none:
from argparse import ArgumentParser
p = ArgumentParser('replay', description='replays a xonsh history file')
p.add_argument('--merge-envs', dest='merge_envs', default=DEFAULT_MERGE_ENVS,
nargs='+',
help="Describes how to merge the environments, in order of "
@ -96,17 +98,22 @@ def _create_parser():
p.add_argument('-o', '--target', dest='target', default=None,
help='path to new history file')
p.add_argument('path', help='path to replay history file')
_REPLAY_PARSER = p
if p_was_none:
_REPLAY_PARSER = p
return p
def main(args, stdin=None):
"""Acts as main function for replaying a xonsh history file."""
parser = _create_parser()
ns = parser.parse_args(args)
def _main_action(ns, h=None):
replayer = Replayer(ns.path)
hist = replayer.replay(merge_envs=ns.merge_envs, target=ns.target)
print('------------------------------------------------------------')
print('Just replayed history, new history has following information')
print('------------------------------------------------------------')
history_info(ns, hist)
def main(args, stdin=None):
"""Acts as main function for replaying a xonsh history file."""
parser = _create_parser()
ns = parser.parse_args(args)
_main_action(ns)