Skip to main content

commandtoolutils

commandtoolutils is a Python utility package for creating interactive command line menus.

Installation

You can install the commandtoolutils package from GitHub using pip:

pip install git+https://github.com/jobordu/menutools.git

Usage

Here's a simple example that shows how you can use the commandtoolutils package:

from commandtoolutils import menu, ask_questions

def main():
    # Define the menu structure
    menu_structure = [
        {
            'message': 'Say Hello',
            'function': say_hello,
        },
        {
            'message': 'Sub Menu',
            'function': menu,
            'sub_menu': [
                {
                    'message': 'Say Hi',
                    'function': say_hi,
                },
            ],
        },
        {
            'message': 'Ask Questions',
            'function': ask_some_questions,
        }
    ]

    # Display the menu
    menu(menu_structure)

def say_hello():
    print('Hello!')

def say_hi():
    print('Hi!')

def ask_some_questions():
    questions_and_actions = [
        {
            'question': 'Do you like Python?',
            'function': say_yes,
            'message': 'Great! You selected Yes.',
        },
        {
            'question': 'Do you like Java?',
            'function': say_no,
            'message': 'Too bad! You selected No.',
        }
    ]
    ask_questions(questions_and_actions)

def say_yes():
    print('Yes!')

def say_no():
    print('No!')

if __name__ == '__main__':
    main()

In this example, the main function defines the menu structure and then calls the menu function to display the menu. The menu function takes a list of dictionaries that define the menu options. Each dictionary can contain the following keys:

  • message: The text to display for the menu option.
  • function: The function to call when the menu option is selected.
  • sub_menu: A list of dictionaries that define a sub-menu.

The ask_questions function takes a list of dictionaries that define a set of questions to ask the user. Each dictionary can contain the following keys:

  • question: The text of the question to ask.
  • function: The function to call if the user answers 'yes'.
  • message: The message to display if the user answers 'yes'.

License

MIT

Release files for commandtoolutils 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for commandtoolutils 0.1
File Size Uploaded
commandtoolutils-0.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for commandtoolutils 0.1
File Interpreter ABI Platform
commandtoolutils-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / commandtoolutils-0.1.tar.gz

Download URL commandtoolutils-0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f482568f7e429d9ef5b8bd4c9b8cb21dd8e0465092a32b0f1c0acfde2a665b79
BLAKE2b-256 checksum
How to use checksums
69de9ace073a7eef6d65f48f059550f95475f8f87ee4027ee89e6c257572ba7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / commandtoolutils-0.1-py3-none-any.whl

Download URL commandtoolutils-0.1-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd1db6f14046051fabfee885d314166817913a4109511b86918b7ef3a80131a1
BLAKE2b-256 checksum
How to use checksums
7ec78bd51baa17d8e2a02dee9270de5b7047f16ad4d749663195202cc5260974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page