Skip to content

Commit

Permalink
Merge pull request #20 from YakDriver/cli
Browse files Browse the repository at this point in the history
Add CLI
  • Loading branch information
YakDriver authored Apr 22, 2020
2 parents 8f4db48 + c1a54ea commit edd59c7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.2.4
commit = False
tag = False
tag_name = {new_version}
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion oschmod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"S_IXOTH"
)

__version__ = "0.2.3"
__version__ = "0.2.4"


def get_mode(path):
Expand Down
26 changes: 26 additions & 0 deletions oschmod/cli.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
url = https://github.com/yakdriver/oschmod
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit edd59c7

Please sign in to comment.