From 6158bc537435dfa206d48df2fb786cd873d749e0 Mon Sep 17 00:00:00 2001 From: Shawn Davis Date: Thu, 24 Sep 2020 16:05:01 -0400 Subject: [PATCH] Added udf command for StackScript inputs. --- VERSION.txt | 2 +- docs/source/_data/cloc.csv | 4 +-- docs/source/_includes/overlays.rst | 44 ++++++++++++++++++++++++++ scripttease/library/overlays/common.py | 29 +++++++++++++++++ scripttease/library/overlays/posix.py | 12 +++++++ scripttease/version.py | 4 +-- tests/test_library_overlays_common.py | 14 ++++++++ 7 files changed, 104 insertions(+), 5 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index cd69980..162e5dd 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -6.6.0-d \ No newline at end of file +6.6.1-d \ No newline at end of file diff --git a/docs/source/_data/cloc.csv b/docs/source/_data/cloc.csv index 75ffe50..53a1814 100644 --- a/docs/source/_data/cloc.csv +++ b/docs/source/_data/cloc.csv @@ -1,3 +1,3 @@ files,language,blank,comment,code -22,Python,995,879,1639 -22,SUM,995,879,1639 +22,Python,1044,918,1735 +22,SUM,1044,918,1735 diff --git a/docs/source/_includes/overlays.rst b/docs/source/_includes/overlays.rst index 8a64d6a..2e854bc 100644 --- a/docs/source/_includes/overlays.rst +++ b/docs/source/_includes/overlays.rst @@ -71,6 +71,25 @@ Send a message to Twist. title: Notice url: None +udf +--- + +Create a UDF prompt for a StackScript. + +- name (str): The name of the variable. +- default: The default value. +- example: An example value, instead of a default. +- label (str): The label for the variable. + + +.. code-block:: ini + + [run udf command] + udf: name + default: None + example: None + label: None + virtualenv ---------- @@ -703,6 +722,31 @@ Set permissions on a file or directory. owner: None recursive: False +prompt +------ + +Prompt the user for input. + +- name (str): The programmatic name of the input. +- back_title (str): The back title used with the dialog command. +- choices (str | list): A list of valid choices. +- default: The default value. +- fancy (bool): Use a dialog command for the prompt. +- help_text (str): The text to display with the dialog command. +- label (str): The label for the input. + + +.. code-block:: ini + + [run prompt command] + prompt: name + back_title: Input + choices: None + default: None + fancy: False + help_text: None + label: None + remove ------ diff --git a/scripttease/library/overlays/common.py b/scripttease/library/overlays/common.py index 02ac91e..7e3a90d 100644 --- a/scripttease/library/overlays/common.py +++ b/scripttease/library/overlays/common.py @@ -11,6 +11,7 @@ __all__ = ( "run", "slack", "twist", + "udf", ) # Functions @@ -110,6 +111,33 @@ def twist(message, title="Notice", url=None, **kwargs): return Command(" ".join(a), **kwargs) +def udf(name, default=None, example=None, label=None, **kwargs): + """Create a UDF prompt for a StackScript. + + - name (str): The name of the variable. + - default: The default value. + - example: An example value, instead of a default. + - label (str): The label for the variable. + + """ + kwargs.setdefault("prompt for %s in stackscript" % name) + + label = label or name.replace("_", " ").title() + + a = ['# ") + + return Command(" ".join(a), **kwargs) + + # Mappings COMMON_MAPPINGS = { @@ -117,5 +145,6 @@ COMMON_MAPPINGS = { 'run': run, 'slack': slack, 'twist': twist, + 'udf': udf, 'virtualenv': python_virtualenv, } diff --git a/scripttease/library/overlays/posix.py b/scripttease/library/overlays/posix.py index f2881e3..37bf61b 100644 --- a/scripttease/library/overlays/posix.py +++ b/scripttease/library/overlays/posix.py @@ -316,6 +316,17 @@ def perms(path, group=None, mode=None, owner=None, recursive=False, **kwargs): def prompt(name, back_title="Input", choices=None, default=None, fancy=False, help_text=None, label=None, **kwargs): + """Prompt the user for input. + + - name (str): The programmatic name of the input. + - back_title (str): The back title used with the dialog command. + - choices (str | list): A list of valid choices. + - default: The default value. + - fancy (bool): Use a dialog command for the prompt. + - help_text (str): The text to display with the dialog command. + - label (str): The label for the input. + + """ return Prompt( name, back_title=back_title, @@ -720,6 +731,7 @@ POSIX_MAPPINGS = { 'mkdir': mkdir, 'move': move, 'perms': perms, + 'prompt': prompt, 'remove': remove, 'rename': rename, 'rsync': rsync, diff --git a/scripttease/version.py b/scripttease/version.py index 9635814..debc656 100644 --- a/scripttease/version.py +++ b/scripttease/version.py @@ -1,5 +1,5 @@ DATE = "2020-09-24" -VERSION = "6.6.0-d" +VERSION = "6.6.1-d" MAJOR = 6 MINOR = 6 -PATCH = 0 +PATCH = 1 diff --git a/tests/test_library_overlays_common.py b/tests/test_library_overlays_common.py index 7aca5f4..c5f638c 100644 --- a/tests/test_library_overlays_common.py +++ b/tests/test_library_overlays_common.py @@ -41,3 +41,17 @@ def test_twist(): c = twist("This is a test.", url="https://example.twist.com/asdf/1234") s = c.get_statement(suppress_comment=True) print(s) + + +def test_udf(): + c = udf("testing") + s = c.get_statement() + assert s == '# ' + + c = udf("testing", default="yes") + s = c.get_statement() + assert s == '# ' + + c = udf("testing", example="example.com") + s = c.get_statement() + assert s == '# '