diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d0bd8e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +build: piggybank + python setup.py sdist bdist_wheel +install: + python -m pip install --upgrade dist/piggybank-1.0.0-py3-none-any.whl +uninstall: + python -m pip uninstall piggybank +clean: + rm -rf piggybank/__pycache__ piggybank/cli/__pycache__ \ + build dist piggybank.egg-info \ No newline at end of file diff --git a/bi.cmd b/bi.cmd deleted file mode 100644 index fa1d801..0000000 --- a/bi.cmd +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -python setup.py sdist bdist_wheel -python -m pip install --user --upgrade dist/piggybank-1.0.0-py3-none-any.whl -pause diff --git a/bi.sh b/bi.sh deleted file mode 100644 index ec93258..0000000 --- a/bi.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/sh -python setup.py sdist bdist_wheel -python -m pip install --upgrade dist/piggybank-1.0.0-py3-none-any.whl diff --git a/piggybank/cli/main.py b/piggybank/cli/main.py new file mode 100644 index 0000000..e8d8e17 --- /dev/null +++ b/piggybank/cli/main.py @@ -0,0 +1,70 @@ +from re import match +from sys import argv + +from piggybank import print_program_version +from piggybank.currencies import print_supported_currencies + + +USAGE_PUT = "Usage: piggybank put [-r|--reversed] COINS in FILE of CURRENCY\n" \ + "Put a set of coins in a piggybank. Set a currency of a new one.\n\n" \ + "-r, --reversed -- use reversed order of COINS (from greater to least);\n" \ + "COINS -- array of comma or whitespace separated coins;\n" \ + "in FILE -- .pb file name of your piggybank;\n" \ + "of CURRENCY -- set a currency for a new piggybank.\n" + +USAGE_TAKE = "Take a set of coins from a piggybank.\n" \ + "Usage: piggybank take [-r|--reversed] COINS from FILE\n\n" \ + "-r, --reversed -- use reversed order of COINS (from greater to least);\n" \ + "COINS -- array of comma or whitespace separated coins;\n" \ + "from FILE -- .pb file of your piggybank.\n" \ + +USAGE_SHOW = "Show statistics about a piggybank.\n" \ + "Usage: piggybank show FILE [with t,transactions]\n\n" \ + "FILE -- .pb file name of your piggybank;\n" \ + "with t,transaction -- list all transactions.\n" + +HELP = "Usage: piggybank [put | take | show] [-v | --version] " \ + "[-h | --help] [-L | --list-currencies]\n\n" \ + f"{USAGE_PUT}\n" \ + f"{USAGE_TAKE}\n" \ + f"{USAGE_SHOW}\n\n" \ + "-L,--list-currencies -- list all supported currencies and a default one;" \ + "-v,--version -- print version of a program;\n" \ + "-h,--help -- print this help.\n" + +def put(args): + r = r"^put(?P -r| --reversed)? (?P[\d ,]+) in (?P\S+)(?= of (?P\w+))?" + +def take(args): + r = r"^take(?P -r| --reversed)? (?P[\d ,]+) from (?P\S+)" + +def show(args): + r = r"^show (?P\S+)(?= with (?Pt|transactions))?" + +def common(args): + r = r"(?P-v|--version)?(?P-h|--help)?(?P-L|--list-currencies)?" + argd = match(r, args).groupdict() + + if not argd["version"] is None: + print_program_version() + exit() + elif not argd["help"] is None: + print(HELP) + elif not argd["list_currencies"] is None: + print_supported_currencies() + +def main(): + command = argv[1] + args_str = " ".join(argv[1:]) + if command == "put": + put(args_str) + elif command == "take": + take(args_str) + elif command == "show": + show(args_str) + else: + common(args_str) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 239328f..a845ef3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,7 @@ long_description = file: README.md long_description_content_type = text/markdown author = attr: piggybank.__author__ author_email = attr: piggybank.__email__ -url = https://aravs.ru +url = https://arav.top keywords = coins piggy bank @@ -16,6 +16,7 @@ keywords = savings license = WTFPL 2.0 license_file = COPYING +platforms=OS Independent classifiers = Development Status :: 5 - Production/Stable Environment :: Console @@ -28,7 +29,7 @@ classifiers = [options] zip_safe = False -python_requires = >=3.7 +python_requires = >=3.6 include_package_data = True packages = find: