Use pysheller library to parse commands
This commit is contained in:
parent
122ac7e8b4
commit
11b8331037
@ -1,36 +1,13 @@
|
|||||||
from os import listdir, path
|
from pysheller import PySheller
|
||||||
from argparse import ArgumentParser
|
from os import chdir
|
||||||
from subprocess import call
|
from os.path import dirname, realpath, join
|
||||||
|
|
||||||
dir_path = path.join(path.dirname(path.realpath(__file__)), "commands")
|
|
||||||
|
|
||||||
|
|
||||||
def parse_comments(command: str) -> dict:
|
|
||||||
with open(path.join(dir_path, f"{command}.sh"), "r") as f:
|
|
||||||
lines = f.read().splitlines()
|
|
||||||
comments = [
|
|
||||||
l.replace("# ", "")
|
|
||||||
for l in lines
|
|
||||||
if l.startswith("#") and not l.startswith("#!")
|
|
||||||
]
|
|
||||||
return {key: val.strip() for key, val in (line.split(":") for line in comments)}
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
commands = [x.replace(".sh", "") for x in listdir(dir_path)]
|
dir_path = dirname(realpath(__file__))
|
||||||
|
|
||||||
parser = ArgumentParser(
|
PySheller(
|
||||||
prog="guzzy",
|
name="guzzy",
|
||||||
description="Interactive CLI git client inside fzf.",
|
description="Interactive CLI git client inside fzf.",
|
||||||
allow_abbrev=False,
|
commands_dir=join(dir_path, "commands"),
|
||||||
)
|
)
|
||||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
||||||
|
|
||||||
subcommands = {}
|
|
||||||
for cmd in commands:
|
|
||||||
p = parse_comments(cmd)
|
|
||||||
subcommands[cmd] = subparsers.add_parser(cmd, help=p["help"])
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
call(path.join(dir_path, f"{args.command}.sh"), shell=True)
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# help : list all commits where file was changed and display diff for each one
|
# help : list all commits where file was changed and display diff for each one
|
||||||
|
# arg1 : filename - name of the file to show history of
|
||||||
|
|
||||||
file_name="$1"
|
file_name="$1"
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# help : list all files in specified commit/tag/branch with preview
|
# help : list all files in specified commit/tag/branch with preview
|
||||||
|
# arg1 : commit - commit hash, branch or tag name
|
||||||
|
|
||||||
[ "$1" ] && commit_hash="$1" || commit_hash="HEAD"
|
[ "$1" ] && commit_hash="$1" || commit_hash="HEAD"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user