Added udf command for StackScript inputs.

development
Shawn Davis 4 years ago
parent 761e0ede1a
commit 6158bc5374
  1. 2
      VERSION.txt
  2. 4
      docs/source/_data/cloc.csv
  3. 44
      docs/source/_includes/overlays.rst
  4. 29
      scripttease/library/overlays/common.py
  5. 12
      scripttease/library/overlays/posix.py
  6. 4
      scripttease/version.py
  7. 14
      tests/test_library_overlays_common.py

@ -1 +1 @@
6.6.0-d
6.6.1-d

@ -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

1 files language blank comment code
2 22 Python 995 1044 879 918 1639 1735
3 22 SUM 995 1044 879 918 1639 1735

@ -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
------

@ -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 = ['# <UDF name="%s" label="%s"' % (name, label)]
if default is not None:
a.append('default="%s"' % default)
elif example is not None:
a.append('example="%s"' % example)
else:
pass
a.append("/>")
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,
}

@ -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,

@ -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

@ -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 == '# <UDF name="testing" label="Testing" />'
c = udf("testing", default="yes")
s = c.get_statement()
assert s == '# <UDF name="testing" label="Testing" default="yes" />'
c = udf("testing", example="example.com")
s = c.get_statement()
assert s == '# <UDF name="testing" label="Testing" example="example.com" />'

Loading…
Cancel
Save