the Lord knows what
This commit is contained in:
parent
e939923a3f
commit
7590597e3e
36
plug
36
plug
@ -56,6 +56,7 @@ def usage():
|
|||||||
{C[g]}{C[B]}--color{C[n]} {C[B]}{C[b]}never{C[y]}|{C[b]}auto{C[y]}|{C[b]}always{C[n]} : set output coloring option; default: auto
|
{C[g]}{C[B]}--color{C[n]} {C[B]}{C[b]}never{C[y]}|{C[b]}auto{C[y]}|{C[b]}always{C[n]} : set output coloring option; default: auto
|
||||||
{C[g]}{C[B]}-d{C[n]} {C[b]}{C[B]}<name> <value>{C[n]} : define placeholder on the cli
|
{C[g]}{C[B]}-d{C[n]} {C[b]}{C[B]}<name> <value>{C[n]} : define placeholder on the cli
|
||||||
{C[g]}{C[B]}-e{C[n]} {C[b]}{C[B]}<name> <file>{C[n]} : define placeholder as the contents of <file>
|
{C[g]}{C[B]}-e{C[n]} {C[b]}{C[B]}<name> <file>{C[n]} : define placeholder as the contents of <file>
|
||||||
|
{C[g]}{C[B]}-a{C[n]} : define all undefined placeholders as empty strings
|
||||||
{C[g]}{C[B]}-u{C[n]} : ungenerate placeholders (ie. collapse)
|
{C[g]}{C[B]}-u{C[n]} : ungenerate placeholders (ie. collapse)
|
||||||
{C[g]}{C[B]}-g{C[n]} : generate placeholders (ie. expand)
|
{C[g]}{C[B]}-g{C[n]} : generate placeholders (ie. expand)
|
||||||
Every argument not starting with '-' is considered a file.
|
Every argument not starting with '-' is considered a file.
|
||||||
@ -87,6 +88,7 @@ def usage():
|
|||||||
|
|
||||||
destination_files = []
|
destination_files = []
|
||||||
operation = ""
|
operation = ""
|
||||||
|
is_all = False
|
||||||
|
|
||||||
placeholders = {}
|
placeholders = {}
|
||||||
|
|
||||||
@ -120,6 +122,8 @@ def builtin_lookup(phl : str) -> str:
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def gen(s : str, phls : [str]) -> str:
|
def gen(s : str, phls : [str]) -> str:
|
||||||
|
global is_all
|
||||||
|
s = ungen(s, phls)
|
||||||
for phl in phls:
|
for phl in phls:
|
||||||
buf = ''
|
buf = ''
|
||||||
l = 0
|
l = 0
|
||||||
@ -132,10 +136,20 @@ def gen(s : str, phls : [str]) -> str:
|
|||||||
l = m.end(0)
|
l = m.end(0)
|
||||||
buf += s[l:]
|
buf += s[l:]
|
||||||
s = buf
|
s = buf
|
||||||
|
if is_all:
|
||||||
|
buf = ''
|
||||||
|
l = 0
|
||||||
|
for m in re_placeholder_collapsed.finditer(s):
|
||||||
|
buf += s[l : m.start(0)]
|
||||||
|
buf += m.group(1) + placeholder_expanded_beginning.format(m.group(2)) + '\n'
|
||||||
|
buf += m.group(1) + placeholder_expanded_ending.format(m.group(2))
|
||||||
|
l = m.end(0)
|
||||||
|
buf += s[l:]
|
||||||
|
s = buf
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def ungen(s : str, phls : [str]) -> str:
|
def ungen(s : str, phls : [str]) -> str:
|
||||||
|
global is_all
|
||||||
for phl in phls:
|
for phl in phls:
|
||||||
buf = ''
|
buf = ''
|
||||||
l = 0
|
l = 0
|
||||||
@ -150,6 +164,19 @@ def ungen(s : str, phls : [str]) -> str:
|
|||||||
break
|
break
|
||||||
buf += s[l:]
|
buf += s[l:]
|
||||||
s = buf
|
s = buf
|
||||||
|
if is_all:
|
||||||
|
buf = ''
|
||||||
|
l = 0
|
||||||
|
for m in re_placeholder_expanded_beginning.finditer(s):
|
||||||
|
buf += s[l : m.start(0)]
|
||||||
|
buf += m.group(1) + placeholder_collapsed.format(m.group(2))
|
||||||
|
l = m.end(0)
|
||||||
|
for me in re_placeholder_expanded_ending.finditer(s[m.end(0):]):
|
||||||
|
if(me.group(1) != m.group(2)): continue
|
||||||
|
l = m.end(0) + me.end(0)
|
||||||
|
break
|
||||||
|
buf += s[l:]
|
||||||
|
s = buf
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def error_and_quit(e : int, argv : [str]) -> None:
|
def error_and_quit(e : int, argv : [str]) -> None:
|
||||||
@ -169,7 +196,7 @@ def error_and_quit(e : int, argv : [str]) -> None:
|
|||||||
|
|
||||||
# We need this function because getopt does not support a single flag taking 2 arguments
|
# We need this function because getopt does not support a single flag taking 2 arguments
|
||||||
def parse_args(argv : [str]) -> None:
|
def parse_args(argv : [str]) -> None:
|
||||||
global destination_files, operation
|
global destination_files, operation, is_all
|
||||||
def get_param(argv : [str], i : int) -> str:
|
def get_param(argv : [str], i : int) -> str:
|
||||||
try: param = argv[i]
|
try: param = argv[i]
|
||||||
except: error_and_quit(Error.PARAM_MISS, [argv[i-1]])
|
except: error_and_quit(Error.PARAM_MISS, [argv[i-1]])
|
||||||
@ -190,6 +217,11 @@ def parse_args(argv : [str]) -> None:
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if argv[i] == '-a':
|
||||||
|
is_all = True
|
||||||
|
i = i + 1
|
||||||
|
continue
|
||||||
|
|
||||||
# 1 param opt
|
# 1 param opt
|
||||||
if argv[i-1] == '--color':
|
if argv[i-1] == '--color':
|
||||||
p = get_param(argv, i)
|
p = get_param(argv, i)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user