Skip to content

Commit

Permalink
Smartcliapp v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smartlegionlab committed May 8, 2024
1 parent 4ecc6fe commit 1867550
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include LICENSE
include README.md
include requirements.txt
include tox.ini
include setup.cfg
include setup.py
global-exclude tests/*
global-exclude data/*
global-exclude requirements/*
119 changes: 118 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,119 @@
# smartcliapp
Cross-platform library of tools for creating console applications, based on the click library.

***

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/smartlegionlab/smartcliapp)](https://github.com/smartlegionlab/smartcliapp/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/smartcliapp?label=pypi%20downloads)](https://pypi.org/project/smartcliapp/)
![GitHub top language](https://img.shields.io/github/languages/top/smartlegionlab/smartcliapp)
[![PyPI](https://img.shields.io/pypi/v/smartcliapp)](https://pypi.org/project/smartcliapp)
[![GitHub](https://img.shields.io/github/license/smartlegionlab/smartcliapp)](https://github.com/smartlegionlab/smartcliapp/blob/master/LICENSE)
[![PyPI - Format](https://img.shields.io/pypi/format/smartcliapp)](https://pypi.org/project/smartcliapp)

***

## Short Description:

___smartcliapp___ - Cross-platform library of tools for creating console applications, based on the click library.

***

Author and developer: ___A.A Suvorov___

[![smartlegiondev@gmail.com](https://img.shields.io/static/v1?label=email:&message=smartlegiondev@gmail.com&color=blue)](mailto:smartlegiondev@gmail.com)

***

## Supported:

- Linux: All.
- Windows: 7/8/10.
- Termux (Android).

***

## What's new?

___smartcliapp v0.4.0___

## Warning!

The package is under active development, so new versions
may not be compatible with the old ones.

***

## Description:

___smartcliapp___ - Cross-platform library of tools for creating console applications, based on the click library.

Use a variety of out-of-the-box tools to create console applications.

Use [click](https://github.com/pallets/click) to develop console applications.


### Possibilities:

- Displays the title and footer of the application at startup and shutdown. In the center of the console.
- Display of name, description, copyright, site address in your application.
- Launch the default browser from the console to go to the specified URL, or to your site.
- Storing meta information about your application in one place.
- Request for action from the user with an instant response to his input without confirmation, consent, refusal, exit from the application (yes/no/exit).
- Various input methods, including non-display input for passwords.
- Operation status output (Ok!/Error!).
- Different ways of displaying information (normal, in the center of the console with filling with characters, in a pager).
- Top-level ready-made classes containing the necessary tools.
- Factory for creating objects.

- Use Informer to display meta information.
- Use ClickMan as a toolbox (Printer, InputMan, StatusMan, ActionMan, Launcher).
- Use Factory to create objects individually.

***

## Help:

### Install:

- `pip install smartcliapp`

### Use:

```python
from smartcliapp import Informer, CliManager

class CliMan(Informer):
tools = CliManager()
name = 'App Name'
title = 'App title'
description = 'App Description'
copyright = 'App copyright'
url = 'app url'
msg = ''
version = '0.0.0'

```

***

## Disclaimer of liability:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

***

## Copyright:
--------------------------------------------------------
Licensed under the terms of the BSD 3-Clause License
(see LICENSE for details).
Copyright © 2018-2024, A.A Suvorov
All rights reserved.
--------------------------------------------------------
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-architect
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setuptools~=57.0.0
smartprinter~=0.2.0
click~=8.0.1
6 changes: 6 additions & 0 deletions requirements/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest
pytest-cov
tox
build
smartprinter~=0.1.1
click~=8.0.1
3 changes: 3 additions & 0 deletions requirements/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
tox
build
47 changes: 47 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[metadata]
name = smartcliapp
version = attr: smartcliapp.__version__
author = A.A Suvorov
author_email = smartlegiondev@gmail.com
description = 'Cross-platform library of tools for creating console applications, based on the click library.'
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/smartlegionlab
project_urls =
Documentation = https://github.com/smartlegionlab/smartcliapp/blob/master/README.md
Release notes = https://github.com/smartlegionlab/smartcliapp/releases
license = BSD 3-Clause License
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: End Users/Desktop
Intended Audience :: System Administrators
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: OS Independent
Operating System :: Microsoft :: Windows
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3 :: Only
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Utilities
keywords =
smartlegionlab
click
smart cli app
console application
create cli

[options]
python_requires = >=3.6
packages = find:
include_package_data = true
zip_safe = false
install_requires =
smartprinter~=0.2.0
click~=8.0.1

[coverage:run]
omit =
venv/*
.pytest_cache
*__init__.py
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
from setuptools import setup, find_packages

setup(
packages=find_packages(exclude=("tests", "data", "requirements")),
)
11 changes: 11 additions & 0 deletions smartcliapp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
"""Cross-platform library of tools for creating console
applications, based on the click library."""
from smartcliapp.climanager import CliManager
from smartcliapp.informer import Informer
__version__ = '0.4.0'
79 changes: 79 additions & 0 deletions smartcliapp/climanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
import sys

import click
from smartprinter.printers import Printer


class CliManager:

def __init__(self):
self.printer = Printer()

def to_continue(self, msg=None):
if msg is None:
msg = 'Enter to continue...'
return self.input(msg)

@staticmethod
def input(msg):
return input(msg)

def get_action(self, title: str) -> bool:
"""
Get Action
- Yes, No , Exit
:param title: Title string
:return: <bool> - yes/no True/False
"""
while 1:
self.printer.base.echo(f'{title} [y/n/e]: ')
char = click.getchar()

if char.lower() in ('y', 'н',):
return True
elif char.lower() in ('n', 'т',):
return False
elif char.lower() in ('e', 'у'):
sys.exit(0)

@staticmethod
def launch(url):
"""
Launch the default browser to follow the specified link.
:param url: <str> url;
:return: None;
"""
click.launch(url)

@classmethod
def prompt(cls, title, hide_input=False):
"""
Click input.
:param title: <str> title;
:param hide_input: <bool> - hidden input. y/n True/False
:return:
"""
return click.prompt(title, hide_input=hide_input)

def show_status(self, status, show=True):
"""
Status output.
:param status: <bool> - True/False;
:param show: <bool> - Print to Console/Do Not Print;
:return: <str> status message;
"""
msg = 'Ok!' if status else 'Error!'
if show:
self.printer.base.echo(msg)
return msg
36 changes: 36 additions & 0 deletions smartcliapp/informer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
from smartprinter.printers import Printer


class Informer:
"""
Informer
- Override the attributes to yours.
"""
printer = Printer()
name = ''
title = ''
description = ''
copyright = ''
url = ''
msg = ''
version = '0.0.0'

@classmethod
def show_head(cls, char='*'):
"""Displays a header with information when the application starts."""
cls.printer.smart.echo(char=char)
cls.printer.smart.echo(cls.title, char=char)
cls.printer.smart.echo(cls.description, char=char)

@classmethod
def show_footer(cls, char='*'):
"""Displays a footer with information when the application ends."""
cls.printer.smart.echo(cls.url, char=char)
cls.printer.smart.echo(cls.copyright, char=char)
cls.printer.smart.echo(char=char)
10 changes: 10 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tox]
envlist =
py{39,38,37,36}

[testenv]
deps =
-r requirements/requirements-test.txt

commands =
python setup.py install

0 comments on commit 1867550

Please sign in to comment.