-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |