mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
Merge pull request #925 from adqm/prevent_wiz
Add option to prevent config wizard starting every time xonsh is run
This commit is contained in:
commit
62354964e5
2 changed files with 21 additions and 8 deletions
|
@ -212,9 +212,9 @@ class StateFile(Input):
|
|||
given file name. This node type is likely not useful on its own.
|
||||
"""
|
||||
|
||||
attrs = ('default_file', 'check')
|
||||
attrs = ('default_file', 'check', 'ask_filename')
|
||||
|
||||
def __init__(self, default_file=None, check=True):
|
||||
def __init__(self, default_file=None, check=True, ask_filename=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_filename : 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_filename
|
||||
self.default_file = default_file
|
||||
self.check = check
|
||||
|
||||
|
@ -384,8 +388,8 @@ class PrettyFormatter(Visitor):
|
|||
return s
|
||||
|
||||
def visit_statefile(self, node):
|
||||
s = '{0}(default_file={1!r}, check={2})'
|
||||
s = s.format(node.__class__.__name__, node.default_file, node.check)
|
||||
s = '{0}(default_file={1!r}, check={2}, ask_filename={3})'
|
||||
s = s.format(node.__class__.__name__, node.default_file, node.check, node.ask_filename)
|
||||
return s
|
||||
|
||||
def visit_while(self, node):
|
||||
|
@ -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):
|
||||
|
|
|
@ -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_filename=False, default_file=default_file)
|
||||
wiz = Question(q, {1: wiz, 2: passer, 3: saver},
|
||||
converter=lambda x: int(x) if x != '' else 2)
|
||||
return wiz
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue