%global _empty_manifest_terminate_build 0 Name: python-cliar Version: 1.3.5 Release: 1 Summary: Create CLIs with classes and type hints. License: MIT URL: https://moigagoo.github.io/cliar/ Source0: https://mirrors.nju.edu.cn/pypi/web/packages/bc/c0/e449bd83c9128c22cdd50e0dbc2b49b0c7fd980af765b35f492e37d0d95b/cliar-1.3.5.tar.gz BuildArch: noarch %description [![image](https://img.shields.io/pypi/v/cliar.svg)](https://pypi.org/project/cliar) [![Build Status](https://travis-ci.com/moigagoo/cliar.svg?branch=develop)](https://travis-ci.com/moigagoo/cliar) [![image](https://codecov.io/gh/moigagoo/cliar/branch/develop/graph/badge.svg)](https://codecov.io/gh/moigagoo/cliar) # Cliar **Cliar** is a Python package to help you create commandline interfaces. It focuses on simplicity and extensibility: - Creating a CLI is as simple as subclassing from `cliar.Cliar`. - Extending a CLI is as simple as subclassing from a `cliar.Cliar` subclass. Cliar's mission is to let you focus on the business logic instead of building an interface for it. At the same time, Cliar doesn't want to stand in your way, so it provides the means to customize the generated CLI. ## Installation ```shell $ pip install cliar ``` Cliar requires Python 3.6+ and is tested on Windows, Linux, and macOS. There are no dependencies outside Python's standard library. ## Basic Usage Let's create a commandline calculator that adds two floats: ```python from cliar import Cliar class Calculator(Cliar): '''Calculator app.''' def add(self, x: float, y: float): '''Add two numbers.''' print(f'The sum of {x} and {y} is {x+y}.') if __name__ == '__main__': Calculator().parse() ``` Save this code to `calc.py` and run it. Try different inputs: - Valid input: $ python calc.py add 12 34 The sum of 12.0 and 34.0 is 46.0. - Invalid input: $ python calc.py add foo bar usage: calc.py add [-h] x y calc.py add: error: argument x: invalid float value: 'foo' - Help: $ python calc.py -h usage: calc.py [-h] {add} ... Calculator app. optional arguments: -h, --help show this help message and exit commands: {add} Available commands: add Add two numbers. - Help for `add` command: $ python calc.py add -h usage: calc.py add [-h] x y Add two numbers. positional arguments: x y optional arguments: -h, --help show this help message and exit A few things to note: - It's a regular Python class with a regular Python method. You don't need to learn any new syntax to use Cliar. - `add` method is converted to `add` command, its positional params are converted to positional commandline args. - There is no explicit conversion to float for `x` or `y` or error handling in the `add` method body. Instead, `x` and `y` are just treated as floats. Cliar converts the types using `add`'s type hints. Invalid input doesn't even reach your code. - `--help` and `-h` flags are added automatically and the help messages are generated from the docstrings. ## Setuptools and Poetry To invoke your CLI via an entrypoint, wrap `parse` call in a function and point to it in your `setup.py` or `pyproject.toml`. `calc.py`: ... def entry_point(): Calculator().parse() `setup.py`: setup( ... entry_points = { 'console_scripts': ['calc=calc:entry_point'], } ... ) `pyproject.toml`: ... [tool.poetry.scripts] calc = 'calc:entry_point' ## Read Next - [Tutorial →](https://moigagoo.github.io/cliar/tutorial/) - [Cliar vs. Click vs. docopt →](https://moigagoo.github.io/cliar/comparison/) %package -n python3-cliar Summary: Create CLIs with classes and type hints. Provides: python-cliar BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-cliar [![image](https://img.shields.io/pypi/v/cliar.svg)](https://pypi.org/project/cliar) [![Build Status](https://travis-ci.com/moigagoo/cliar.svg?branch=develop)](https://travis-ci.com/moigagoo/cliar) [![image](https://codecov.io/gh/moigagoo/cliar/branch/develop/graph/badge.svg)](https://codecov.io/gh/moigagoo/cliar) # Cliar **Cliar** is a Python package to help you create commandline interfaces. It focuses on simplicity and extensibility: - Creating a CLI is as simple as subclassing from `cliar.Cliar`. - Extending a CLI is as simple as subclassing from a `cliar.Cliar` subclass. Cliar's mission is to let you focus on the business logic instead of building an interface for it. At the same time, Cliar doesn't want to stand in your way, so it provides the means to customize the generated CLI. ## Installation ```shell $ pip install cliar ``` Cliar requires Python 3.6+ and is tested on Windows, Linux, and macOS. There are no dependencies outside Python's standard library. ## Basic Usage Let's create a commandline calculator that adds two floats: ```python from cliar import Cliar class Calculator(Cliar): '''Calculator app.''' def add(self, x: float, y: float): '''Add two numbers.''' print(f'The sum of {x} and {y} is {x+y}.') if __name__ == '__main__': Calculator().parse() ``` Save this code to `calc.py` and run it. Try different inputs: - Valid input: $ python calc.py add 12 34 The sum of 12.0 and 34.0 is 46.0. - Invalid input: $ python calc.py add foo bar usage: calc.py add [-h] x y calc.py add: error: argument x: invalid float value: 'foo' - Help: $ python calc.py -h usage: calc.py [-h] {add} ... Calculator app. optional arguments: -h, --help show this help message and exit commands: {add} Available commands: add Add two numbers. - Help for `add` command: $ python calc.py add -h usage: calc.py add [-h] x y Add two numbers. positional arguments: x y optional arguments: -h, --help show this help message and exit A few things to note: - It's a regular Python class with a regular Python method. You don't need to learn any new syntax to use Cliar. - `add` method is converted to `add` command, its positional params are converted to positional commandline args. - There is no explicit conversion to float for `x` or `y` or error handling in the `add` method body. Instead, `x` and `y` are just treated as floats. Cliar converts the types using `add`'s type hints. Invalid input doesn't even reach your code. - `--help` and `-h` flags are added automatically and the help messages are generated from the docstrings. ## Setuptools and Poetry To invoke your CLI via an entrypoint, wrap `parse` call in a function and point to it in your `setup.py` or `pyproject.toml`. `calc.py`: ... def entry_point(): Calculator().parse() `setup.py`: setup( ... entry_points = { 'console_scripts': ['calc=calc:entry_point'], } ... ) `pyproject.toml`: ... [tool.poetry.scripts] calc = 'calc:entry_point' ## Read Next - [Tutorial →](https://moigagoo.github.io/cliar/tutorial/) - [Cliar vs. Click vs. docopt →](https://moigagoo.github.io/cliar/comparison/) %package help Summary: Development documents and examples for cliar Provides: python3-cliar-doc %description help [![image](https://img.shields.io/pypi/v/cliar.svg)](https://pypi.org/project/cliar) [![Build Status](https://travis-ci.com/moigagoo/cliar.svg?branch=develop)](https://travis-ci.com/moigagoo/cliar) [![image](https://codecov.io/gh/moigagoo/cliar/branch/develop/graph/badge.svg)](https://codecov.io/gh/moigagoo/cliar) # Cliar **Cliar** is a Python package to help you create commandline interfaces. It focuses on simplicity and extensibility: - Creating a CLI is as simple as subclassing from `cliar.Cliar`. - Extending a CLI is as simple as subclassing from a `cliar.Cliar` subclass. Cliar's mission is to let you focus on the business logic instead of building an interface for it. At the same time, Cliar doesn't want to stand in your way, so it provides the means to customize the generated CLI. ## Installation ```shell $ pip install cliar ``` Cliar requires Python 3.6+ and is tested on Windows, Linux, and macOS. There are no dependencies outside Python's standard library. ## Basic Usage Let's create a commandline calculator that adds two floats: ```python from cliar import Cliar class Calculator(Cliar): '''Calculator app.''' def add(self, x: float, y: float): '''Add two numbers.''' print(f'The sum of {x} and {y} is {x+y}.') if __name__ == '__main__': Calculator().parse() ``` Save this code to `calc.py` and run it. Try different inputs: - Valid input: $ python calc.py add 12 34 The sum of 12.0 and 34.0 is 46.0. - Invalid input: $ python calc.py add foo bar usage: calc.py add [-h] x y calc.py add: error: argument x: invalid float value: 'foo' - Help: $ python calc.py -h usage: calc.py [-h] {add} ... Calculator app. optional arguments: -h, --help show this help message and exit commands: {add} Available commands: add Add two numbers. - Help for `add` command: $ python calc.py add -h usage: calc.py add [-h] x y Add two numbers. positional arguments: x y optional arguments: -h, --help show this help message and exit A few things to note: - It's a regular Python class with a regular Python method. You don't need to learn any new syntax to use Cliar. - `add` method is converted to `add` command, its positional params are converted to positional commandline args. - There is no explicit conversion to float for `x` or `y` or error handling in the `add` method body. Instead, `x` and `y` are just treated as floats. Cliar converts the types using `add`'s type hints. Invalid input doesn't even reach your code. - `--help` and `-h` flags are added automatically and the help messages are generated from the docstrings. ## Setuptools and Poetry To invoke your CLI via an entrypoint, wrap `parse` call in a function and point to it in your `setup.py` or `pyproject.toml`. `calc.py`: ... def entry_point(): Calculator().parse() `setup.py`: setup( ... entry_points = { 'console_scripts': ['calc=calc:entry_point'], } ... ) `pyproject.toml`: ... [tool.poetry.scripts] calc = 'calc:entry_point' ## Read Next - [Tutorial →](https://moigagoo.github.io/cliar/tutorial/) - [Cliar vs. Click vs. docopt →](https://moigagoo.github.io/cliar/comparison/) %prep %autosetup -n cliar-1.3.5 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-cliar -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Tue May 30 2023 Python_Bot - 1.3.5-1 - Package Spec generated