prompt-args


Nameprompt-args JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/justengel/prompt_args
SummaryDecorator to prompt input for missing arguments.
upload_time2023-11-15 20:54:58
maintainer
docs_urlNone
authorJustin Engel
requires_python
licenseProprietary
keywords prompt input args kwargs decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===========
prompt_args
===========

Decorator to prompt input for missing arguments.


Install
=======

.. code-block:: shell

    pip install prompt_args


Usage
=====

.. code-block:: python

    from prompt_args import Prompt

    print("Test automatic prompting")
    @Prompt.decorate
    def my_func(first_name: str, last_name: str = "", status: str = "well"):
        print(f"Hello, {first_name} {last_name}, I am {status}")

    my_func()


    print("\nTest controlled prompting")
    @Prompt.decorate(
        first_name=Prompt("First Name: "),
        last_name=Prompt("Last Name: ", default=""),
        status=Prompt("How are you? ", default="well")
    )
    def my_func(first_name: str, last_name: str, **kwargs):
        print(f"Hello, {first_name} {last_name}, I am {kwargs.get('status')}")

    my_func()
    my_func("Jane", "Doe", status="great")

    # Test error when a prompt is given, but the function argument does not exist
    print("\nTest controlled prompt error")
    try:
        @Prompt.decorate(
            first_name=Prompt("First Name: "),
            last_name=Prompt("Last Name: ", default=""),
            status=Prompt("How are you? ", default="well")
        )
        def my_func(first_name: str, last_name: str):
            print(f"Hello, {first_name} {last_name}")
    except ValueError as e:
        assert "no corresponding function argument" in str(e)


Output

.. code-block:: text

    Test automatic prompting
    Enter First Name: John
    Enter Last Name ['']:
    Enter Status ['well']:
    Hello, John , I am well

    Test controlled prompting
    First Name: John
    Last Name ['']: Doe
    How are you ['well']? just fine
    Hello, John Doe, I am just fine
    Hello, Jane Doe, I am great

    Test controlled prompt error


Register prompt helpers ("Enter ... [{prompt_help}]: ").

.. code-block:: python

    from prompt_args import Prompt

    # Test built in bool converter with Y/n prompt help info
    print("Testing builtin type converter")
    @Prompt.decorate
    def my_func(x: int, confirm: bool = False):
        print(f"Change x to {x}? {confirm}")

    # Test no
    my_func()

    # Test y
    my_func()


    # Test custom type converter
    print("\nTesting custom type converter")
    def long_confirm(value: str) -> bool:
        return value == "Yes I am sure"

    Prompt.register_type_converter(bool, long_confirm, prompt_help="Yes I am sure/no")

    @Prompt.decorate
    def my_super_serious_func(x: int, confirm: bool = False):
        print(f"Change x to {x}? {confirm}")

    # Test invalid y
    my_super_serious_func()

    # Test full Yes I am sure
    my_super_serious_func()

Output:

.. code-block:: text

    Testing builtin type converter
    Enter X: 10
    Enter Confirm [Y/n]: n
    Change x to 10? False
    Enter X: 12
    Enter Confirm [Y/n]: y
    Change x to 12? True

    Testing custom type converter
    Enter X: 20
    Enter Confirm [Yes I am sure/no]: y
    Change x to 20? False
    Enter X: 25
    Enter Confirm [Yes I am sure/no]: Yes I am sure
    Change x to 25? True


Do not prompt for some arguments

.. code-block:: python

    from prompt_args import Prompt

    print("Test no prompting for some arguments")
    @Prompt.decorate(status=Prompt.no_prompt)
    def my_func(first_name: str, last_name: str = "", status: str = "well"):
        print(f"Hello, {first_name} {last_name}, I am {status}")

    # Status should not be prompted
    my_func()

Output

.. code-block:: text

    Test no prompting for some arguments
    Enter First Name: John
    Enter Last Name ['']: Doe
    Hello, John Doe, I am well

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/justengel/prompt_args",
    "name": "prompt-args",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "prompt input args kwargs decorator",
    "author": "Justin Engel",
    "author_email": "jtengel08@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/f5/720c05cb96a986c038d73c7be59809613e5a7fbda79eac8bc49b1142a597/prompt_args-1.0.0.tar.gz",
    "platform": "any",
    "description": "===========\r\nprompt_args\r\n===========\r\n\r\nDecorator to prompt input for missing arguments.\r\n\r\n\r\nInstall\r\n=======\r\n\r\n.. code-block:: shell\r\n\r\n    pip install prompt_args\r\n\r\n\r\nUsage\r\n=====\r\n\r\n.. code-block:: python\r\n\r\n    from prompt_args import Prompt\r\n\r\n    print(\"Test automatic prompting\")\r\n    @Prompt.decorate\r\n    def my_func(first_name: str, last_name: str = \"\", status: str = \"well\"):\r\n        print(f\"Hello, {first_name} {last_name}, I am {status}\")\r\n\r\n    my_func()\r\n\r\n\r\n    print(\"\\nTest controlled prompting\")\r\n    @Prompt.decorate(\r\n        first_name=Prompt(\"First Name: \"),\r\n        last_name=Prompt(\"Last Name: \", default=\"\"),\r\n        status=Prompt(\"How are you? \", default=\"well\")\r\n    )\r\n    def my_func(first_name: str, last_name: str, **kwargs):\r\n        print(f\"Hello, {first_name} {last_name}, I am {kwargs.get('status')}\")\r\n\r\n    my_func()\r\n    my_func(\"Jane\", \"Doe\", status=\"great\")\r\n\r\n    # Test error when a prompt is given, but the function argument does not exist\r\n    print(\"\\nTest controlled prompt error\")\r\n    try:\r\n        @Prompt.decorate(\r\n            first_name=Prompt(\"First Name: \"),\r\n            last_name=Prompt(\"Last Name: \", default=\"\"),\r\n            status=Prompt(\"How are you? \", default=\"well\")\r\n        )\r\n        def my_func(first_name: str, last_name: str):\r\n            print(f\"Hello, {first_name} {last_name}\")\r\n    except ValueError as e:\r\n        assert \"no corresponding function argument\" in str(e)\r\n\r\n\r\nOutput\r\n\r\n.. code-block:: text\r\n\r\n    Test automatic prompting\r\n    Enter First Name: John\r\n    Enter Last Name ['']:\r\n    Enter Status ['well']:\r\n    Hello, John , I am well\r\n\r\n    Test controlled prompting\r\n    First Name: John\r\n    Last Name ['']: Doe\r\n    How are you ['well']? just fine\r\n    Hello, John Doe, I am just fine\r\n    Hello, Jane Doe, I am great\r\n\r\n    Test controlled prompt error\r\n\r\n\r\nRegister prompt helpers (\"Enter ... [{prompt_help}]: \").\r\n\r\n.. code-block:: python\r\n\r\n    from prompt_args import Prompt\r\n\r\n    # Test built in bool converter with Y/n prompt help info\r\n    print(\"Testing builtin type converter\")\r\n    @Prompt.decorate\r\n    def my_func(x: int, confirm: bool = False):\r\n        print(f\"Change x to {x}? {confirm}\")\r\n\r\n    # Test no\r\n    my_func()\r\n\r\n    # Test y\r\n    my_func()\r\n\r\n\r\n    # Test custom type converter\r\n    print(\"\\nTesting custom type converter\")\r\n    def long_confirm(value: str) -> bool:\r\n        return value == \"Yes I am sure\"\r\n\r\n    Prompt.register_type_converter(bool, long_confirm, prompt_help=\"Yes I am sure/no\")\r\n\r\n    @Prompt.decorate\r\n    def my_super_serious_func(x: int, confirm: bool = False):\r\n        print(f\"Change x to {x}? {confirm}\")\r\n\r\n    # Test invalid y\r\n    my_super_serious_func()\r\n\r\n    # Test full Yes I am sure\r\n    my_super_serious_func()\r\n\r\nOutput:\r\n\r\n.. code-block:: text\r\n\r\n    Testing builtin type converter\r\n    Enter X: 10\r\n    Enter Confirm [Y/n]: n\r\n    Change x to 10? False\r\n    Enter X: 12\r\n    Enter Confirm [Y/n]: y\r\n    Change x to 12? True\r\n\r\n    Testing custom type converter\r\n    Enter X: 20\r\n    Enter Confirm [Yes I am sure/no]: y\r\n    Change x to 20? False\r\n    Enter X: 25\r\n    Enter Confirm [Yes I am sure/no]: Yes I am sure\r\n    Change x to 25? True\r\n\r\n\r\nDo not prompt for some arguments\r\n\r\n.. code-block:: python\r\n\r\n    from prompt_args import Prompt\r\n\r\n    print(\"Test no prompting for some arguments\")\r\n    @Prompt.decorate(status=Prompt.no_prompt)\r\n    def my_func(first_name: str, last_name: str = \"\", status: str = \"well\"):\r\n        print(f\"Hello, {first_name} {last_name}, I am {status}\")\r\n\r\n    # Status should not be prompted\r\n    my_func()\r\n\r\nOutput\r\n\r\n.. code-block:: text\r\n\r\n    Test no prompting for some arguments\r\n    Enter First Name: John\r\n    Enter Last Name ['']: Doe\r\n    Hello, John Doe, I am well\r\n",
    "bugtrack_url": null,
    "license": "Proprietary",
    "summary": "Decorator to prompt input for missing arguments.",
    "version": "1.0.0",
    "project_urls": {
        "Download": "https://github.com/justengel/prompt_args/archive/refs/tags/v1.0.0.tar.gz",
        "Homepage": "https://github.com/justengel/prompt_args"
    },
    "split_keywords": [
        "prompt",
        "input",
        "args",
        "kwargs",
        "decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aea7ce4ee6c2a8f44092e05ac1692e65202175f3b3045ddd0d234027bc5d5cfc",
                "md5": "251b7f0fa4f306c50f964f12a600ba45",
                "sha256": "74daa00f3e783b2d52741473bb7a4fd40e5a1b024784d45279367e75097f237c"
            },
            "downloads": -1,
            "filename": "prompt_args-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "251b7f0fa4f306c50f964f12a600ba45",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9063,
            "upload_time": "2023-11-15T20:54:57",
            "upload_time_iso_8601": "2023-11-15T20:54:57.606895Z",
            "url": "https://files.pythonhosted.org/packages/ae/a7/ce4ee6c2a8f44092e05ac1692e65202175f3b3045ddd0d234027bc5d5cfc/prompt_args-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49f5720c05cb96a986c038d73c7be59809613e5a7fbda79eac8bc49b1142a597",
                "md5": "30cb9a8b83a2dbfcba5c0a613713caea",
                "sha256": "ffc208da39e3d0e2c746f00484b9bae14685af025dc4a42be1ea02d270e61b59"
            },
            "downloads": -1,
            "filename": "prompt_args-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "30cb9a8b83a2dbfcba5c0a613713caea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9359,
            "upload_time": "2023-11-15T20:54:58",
            "upload_time_iso_8601": "2023-11-15T20:54:58.903344Z",
            "url": "https://files.pythonhosted.org/packages/49/f5/720c05cb96a986c038d73c7be59809613e5a7fbda79eac8bc49b1142a597/prompt_args-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-15 20:54:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "justengel",
    "github_project": "prompt_args",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "prompt-args"
}
        
Elapsed time: 0.78780s