Skip to content

Commit 812a2f2

Browse files
Improved advanced unroll functionality
1 parent b21fba6 commit 812a2f2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ The file unroll.py can be called from the CLI passing a --file argument to speci
295295

296296
**strip_cmd(nodes)** - Strips all the commands executed from a series of bash nodes in order. No replacement occurs, it simply returns the raw commands.
297297

298-
**advanced_unroll(nodes, var_list={}, fn_dict={}, alias_table={})** - This function strips the commands executed by the series of bash nodes after resolving and command aliasing, function calls, and variable substitutions.
298+
**advanced_unroll(nodes, var_list={}, fn_dict={}, alias_table={}, strip_cmds=True)** - This function resolves command aliasing, function calls, and variable substitutions in a series of bash nodes, replacing as it progresses. The strip_cmds boolean can be toggeled to return only the commands executed or the replaced nodes.
299299

300300

301301

bashparser/unroll.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def apply_fn(node, vstr):
3232
return unrolled_commands
3333

3434

35-
def advanced_unroll(nodes, var_list={}, fn_dict={}, alias_table={}):
35+
def advanced_unroll(nodes, var_list={}, fn_dict={}, alias_table={}, strip_cmds=True):
3636
# The ordering of this function is important. Tread lightly
3737

3838
nodes = bashparser.build_and_resolve_aliasing(nodes, alias_table)
@@ -41,9 +41,13 @@ def advanced_unroll(nodes, var_list={}, fn_dict={}, alias_table={}):
4141

4242
nodes = bashparser.substitute_variables(nodes, var_list)
4343

44-
commands = strip_cmd(nodes)
44+
if strip_cmds:
45+
ret_val = strip_cmd(nodes)
46+
else:
47+
ret_val = nodes
48+
49+
return ret_val
4550

46-
return commands
4751

4852
def main():
4953
import argparse

0 commit comments

Comments
 (0)