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

View file

@ -1,4 +1,5 @@
"""The xonsh configuration (xonfig) utility."""
import os
import ast
import json
import shutil
@ -20,7 +21,8 @@ from xonsh.environ import is_template_string
from xonsh.shell import (is_readline_available, is_prompt_toolkit_available,
prompt_toolkit_version)
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
@ -274,8 +276,13 @@ def make_wizard(default_file=None, confirm=False):
Message(message=WIZARD_TAIL),
])
if confirm:
q = 'Would you like to run the xonsh configuration wizard now, ' + YN
wiz = YesNo(question=q, yes=wiz, no=Pass())
q = ("Would you like to run the xonsh configuration wizard now?\n\n"
"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