add option to prevent config wizard starting every time xonsh is run

This commit is contained in:
adam j hartz 2016-05-18 08:27:33 -04:00
parent b82935f2b2
commit a7ee1bb5d8
2 changed files with 18 additions and 5 deletions

View file

@ -214,7 +214,7 @@ class StateFile(Input):
attrs = ('default_file', 'check') attrs = ('default_file', 'check')
def __init__(self, default_file=None, check=True): def __init__(self, default_file=None, check=True, ask=True):
""" """
Parameters Parameters
---------- ----------
@ -224,10 +224,14 @@ class StateFile(Input):
Whether to print the current state and ask if it should be Whether to print the current state and ask if it should be
saved/loaded prior to asking for the file name and saving the saved/loaded prior to asking for the file name and saving the
file, default=True. file, default=True.
ask : bool, optional
Whether to ask for the filename (if ``False``, always use the
default filename)
""" """
self._df = None self._df = None
super().__init__(prompt='filename: ', converter=None, super().__init__(prompt='filename: ', converter=None,
confirm=False, path=None) confirm=False, path=None)
self.ask_filename = ask
self.default_file = default_file self.default_file = default_file
self.check = check self.check = check
@ -604,6 +608,8 @@ class PromptVisitor(StateVisitor):
do_save = self.visit(asker) do_save = self.visit(asker)
if not do_save: if not do_save:
return Unstorable return Unstorable
fname = None
if node.ask_filename:
fname = self.visit_input(node) fname = self.visit_input(node)
if fname is None or len(fname) == 0: if fname is None or len(fname) == 0:
fname = node.default_file fname = node.default_file

View file

@ -1,4 +1,5 @@
"""The xonsh configuration (xonfig) utility.""" """The xonsh configuration (xonfig) utility."""
import os
import ast import ast
import json import json
import shutil import shutil
@ -20,7 +21,8 @@ from xonsh.environ import is_template_string
from xonsh.shell import (is_readline_available, is_prompt_toolkit_available, from xonsh.shell import (is_readline_available, is_prompt_toolkit_available,
prompt_toolkit_version) prompt_toolkit_version)
from xonsh.wizard import (Wizard, Pass, Message, Save, Load, YesNo, Input, from xonsh.wizard import (Wizard, Pass, Message, Save, Load, YesNo, Input,
PromptVisitor, While, StoreNonEmpty, create_truefalse_cond, YN, Unstorable) PromptVisitor, While, StoreNonEmpty, create_truefalse_cond, YN, Unstorable,
Question)
from xonsh.xontribs import xontrib_metadata, find_xontrib from xonsh.xontribs import xontrib_metadata, find_xontrib
@ -274,8 +276,13 @@ def make_wizard(default_file=None, confirm=False):
Message(message=WIZARD_TAIL), Message(message=WIZARD_TAIL),
]) ])
if confirm: if confirm:
q = 'Would you like to run the xonsh configuration wizard now, ' + YN q = ("Would you like to run the xonsh configuration wizard now?\n\n"
wiz = YesNo(question=q, yes=wiz, no=Pass()) "1. Yes\n2. No, but ask me later.\n3. No, and don't ask me again."
"\n\n1, 2, or 3 [default: 2]? ")
passer = Pass()
saver = Save(check=False, ask=False, default_file=default_file)
wiz = Question(q, {1: wiz, 2: Pass(), 3: saver},
converter=lambda x: int(x.strip()) if x !='' else 2)
return wiz return wiz