Skip to main content

Interactive command line tool.

Project description

PyPI https://img.shields.io/pypi/pyversions/interact-cli.svg?branch=master&color=blue https://img.shields.io/pypi/dm/interact-cli.svg?branch=master&color=blue https://api.travis-ci.com/caizhengxin/interact-cli.svg?branch=master&color=blue Documentation Status https://img.shields.io/github/languages/code-size/caizhengxin/interact-cli.svg?branch=master https://img.shields.io/pypi/l/interact-cli.svg

Interactive command line tool.

Features

  • Interact input

  • Supports multiple data types

  • Support input check

  • Support regex, see network.json

Support type

  • boolean

  • string

  • int

  • float

  • list

  • choice

  • mac

  • ipv4

  • cidr, eg: 192.168.1.1/24

  • hex

Installation

To install interact-cli, run this command in your terminal:

$ pip3 install interact-cli

or:

$ git clone https://github.com/caizhengxin/interact-cli.git
$ cd interact-cli
$ pip3 install -e .

Usage

See interact.json

string:

from interact import interacts


config = {
    "name": {
        "type": "string",
        "default": "jankinca",
        "max_length": 10,
        "min_length": 1,
        "description": "Your name"
    }
}


if __name__ == "__main__":
    """
    Your name [jankinca]: sssssssssssss
    Error: Invalided `sssssssssssss`
    Your name [jankinca]: jankincai
    """

    print(interacts(config).name)

regex:

from interact import interacts


config = {
    "ipv4": {
        "type": "string",
        "regex": r"^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$",
        "default": "192.168.166.12",
        "description": "IPv4 address"
    }
}


if __name__ == "__main__":
    """
    IPv4 address [192.168.166.12]: 22
    Error: Invalided `22`
    IPv4 address [192.168.166.12]: 192.168.166.2
    """

    print(interacts(config).ipv4)

when:

from interact import interacts


config = {
    "use_code_hosting": {
        "type": "boolean",
        "default": True,
        "description": "Use code hosting platform"
    },
    "code_hosting": {
        "type": "choice",
        "default": 1,
        "choice": [
            "github",
            "gitee",
            "gitlab"
        ],
        "description": "Code hosting",
        "when": "use_code_hosting == true"
    },
    "code_hosting_username": {
        "type": "string",
        "default": "jankincai",
        "description": "Your code hosting username",
        "when": "use_code_hosting == true"
    }
}


if __name__ == "__main__":
    """
    Use code hosting platform [y]: y
    Select code hosting:
    1 - github
    2 - gitee
    3 - gitlab
    Choose from [1]:
    Your code hosting username [jankincai]: jankincai

    {'use_code_hosting': True, 'code_hosting': 'github', 'code_hosting_username': 'jankincai'}
    """

    """
    Use code hosting platform [y]: n
    {'use_code_hosting': False, 'code_hosting': None, 'code_hosting_username': None}
    """

    print(interacts(config).get_interact_data())

See demo

Credits

This package was created with Cookiecutter and the caizhengxin/cookiecutter-package project template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interact-cli-0.4.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

interact_cli-0.4.0-py2.py3-none-any.whl (10.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file interact-cli-0.4.0.tar.gz.

File metadata

  • Download URL: interact-cli-0.4.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for interact-cli-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b46f78276e360122c8533ffaaba45337945116c59ec178342db0e32ade2b0d33
MD5 f999ad7c6b83e156b5ced8159fac3f39
BLAKE2b-256 34ffea7b80f08aebbe783fa0d29fff8fb2ca95e9eb613fbb469befd66d9e3588

See more details on using hashes here.

File details

Details for the file interact_cli-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: interact_cli-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for interact_cli-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 294c728d5e82d168bb67e7b36901c28b8a8f85394f4386764019626433417195
MD5 013c7e375abde72adab2b3b6d38e74ea
BLAKE2b-256 31303b8188ac1f74fb876877c01985a41d2bcfb2a63013202fc7af2b22a9cc58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page