forked from Bloomstack/bbscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
53 lines (44 loc) · 888 Bytes
/
cli.py
File metadata and controls
53 lines (44 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import click
import ujson
import bbscript
from bbscript.flags import RepeatStatement
def test_input(ctx):
"""
To get custom user input!
input: Yes/No
If yes
it stores value in user_input of context
"""
if ctx.get("user_input"):
print("We got: ", ctx.get("user_input"))
return
val = input("Say yes: ")
if val == "yes":
ctx["user_input"] = val
return RepeatStatement()
@click.group()
def cli():
pass
@cli.command()
@click.option("--path", help="A bbscript json file to run")
def run(path):
"""
Runs as main function:
input: it takes json file as input
"""
with open(path) as f:
data = ujson.load(f)
rt = bbscript.Runtime({
"input": test_input
}, data)
for l in rt.exec():
pass
@cli.command()
def docs():
"""
It creates a document of the runtime
"""
rt = bbscript.Runtime()
print(rt.docs())
if __name__ == '__main__':
cli()