diff --git a/.bumpversion.cfg b/.bumpversion.cfg index bbcefdd..fc75d7c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.2.4 commit = False tag = False tag_name = {new_version} diff --git a/CHANGELOG.md b/CHANGELOG.md index c95b65e..71e7acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ## Changelog +### 0.2.4 + +**Commit Delta**: [Change from 0.2.2 release](https://github.com/YakDriver/oschmod/compare/0.2.2...0.2.4) + +**Released**: 2020.04.21 + +**Summary**: + +* Add command line interface (CLI). + ### 0.2.2 **Commit Delta**: [Change from 0.2.0 release](https://github.com/YakDriver/oschmod/compare/0.2.0...0.2.2) diff --git a/README.md b/README.md index 45a0d43..95f6640 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,37 @@ import oschmod oschmod.set_mode('myfile', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) ``` +## CLI + +The `oschmod` CLI works similarly to `chmod` albeit with fewer options: + +```console +$ oschmod -h +usage: oschmod [-h] [-R] mode object + +Change the mode (permissions) of a file or directory + +positional arguments: + mode octal mode of the object + object file or directory + +optional arguments: + -h, --help show this help message and exit + -R apply mode recursively +``` + +For example, to open up a file to the world, you can run this command: + +```console +$ oschmod 777 file_name +``` + +As another example, you can lock down a file to just the file owner: + +```console +$ oschmod 700 file_name +``` + ## Installation ```console diff --git a/oschmod/__init__.py b/oschmod/__init__.py index 61f364e..ec2f32d 100644 --- a/oschmod/__init__.py +++ b/oschmod/__init__.py @@ -153,7 +153,7 @@ "S_IXOTH" ) -__version__ = "0.2.3" +__version__ = "0.2.4" def get_mode(path): diff --git a/oschmod/cli.py b/oschmod/cli.py new file mode 100644 index 0000000..7ec3354 --- /dev/null +++ b/oschmod/cli.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +"""pyppyn cli.""" +from __future__ import (absolute_import, division, print_function, + unicode_literals, with_statement) + +import argparse + +import oschmod + + +def main(): + """Provide main function for CLI.""" + parser = argparse.ArgumentParser( + description='Change the mode (permissions) of a file or directory') + parser.add_argument('-R', action='store_true', + help='apply mode recursively') + parser.add_argument('mode', nargs=1, help='octal mode of the object') + parser.add_argument('object', nargs=1, help='file or directory') + + args = parser.parse_args() + mode = int(args.mode[0], 8) + obj = args.object[0] + if args.R: + oschmod.set_mode_recursive(obj, mode) + else: + oschmod.set_mode(obj, mode) diff --git a/setup.cfg b/setup.cfg index 68e0199..e77a984 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ name = oschmod description = Windows and Linux compatible chmod long_description = file: README.md, CHANGELOG.md long_description_content_type = text/markdown -version = 0.2.3 +version = 0.2.4 author = YakDriver author_email = projects@plus3it.com url = https://github.com/yakdriver/oschmod @@ -38,6 +38,11 @@ install_requires = packages = oschmod include_package_data = True +[options.entry_points] +console_scripts = + oschmod = oschmod.cli:main + ochmod = oschmod.cli:main + [bdist_wheel] universal = 1