Skip to content

Commit

Permalink
feat: Add CommandExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2930 committed Sep 19, 2022
1 parent 2476b1c commit 263d68f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# tmpl8

This repository hosts code for the future of templating


## Usage
```
$ tmpl8
usage: tmpl8 [-h] [-v] ...
tmpl8 wrapper for cli commands
positional arguments:
command command to run
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
```
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from importlib.metadata import entry_points
from setuptools import setup
from tmpl8 import __version__

install_requires = [
'pyyaml'
]

setup_options = dict(
name='tmpl8',
version=__version__,
description="Templating wrapper for CLI commands",
author="Matthew Altberg",
install_requires=install_requires,
entry_points={
'console_scripts': [
'tmpl8=tmpl8.cli:main'
Expand Down
13 changes: 11 additions & 2 deletions tmpl8/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import argparse

from tmpl8 import __version__
from tmpl8.extractor import CommandExtractor

def main():
parser = argparse.ArgumentParser(prog='tmpl8', description="tmpl8 wrapper for cli commands")
parser.add_argument('command', help='command to run', nargs=argparse.REMAINDER)
parser.add_argument('-v', action='version', version=__version__)
parser.add_argument('-v', '--version', action='version', version=__version__)

args = parser.parse_args()
print(args.command)

if args.command == []:
parser.print_help()
parser.exit(status=1, message='error: missing command\n')

command = CommandExtractor(args.command)

print(command.files)
21 changes: 21 additions & 0 deletions tmpl8/extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import glob
import os

class CommandExtractor:
files: dict = {}

def __init__(self, command: list):
self.command = command
self._extractFiles()

def _extractFiles(self) -> set:
for i, arg in enumerate(self.command):
for path in glob.glob(arg):
if os.path.isfile(path):
self.files[path] = {'ind': i, 'files': os.path.abspath(path)}
elif os.path.isdir(path):
dir_files = set()
for file in glob.glob(f'{path}/**/*'):
if os.path.isfile(file):
dir_files.add(os.path.abspath(file))
self.files[path] = {'ind': i, 'files': dir_files}

0 comments on commit 263d68f

Please sign in to comment.