-
Notifications
You must be signed in to change notification settings - Fork 0
/
arglib_gui.py
54 lines (41 loc) · 1.49 KB
/
arglib_gui.py
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
54
import argparse
from docker_commands import *
from gooey import Gooey
@Gooey
def main():
# create the parser
parser = argparse.ArgumentParser()
# Create the subparser for `image` and `run`
# dest= is how we can differentiate which argument is used
subparser = parser.add_subparsers(dest='command')
# Creating our different subparsers
pull = subparser.add_parser('pull')
run = subparser.add_parser('run')
# ---image pulling command arguments---
# Sample call: arglib pull <image name>
pull.add_argument('image_name', type=str)
# ---running a container arguments---
# Runs an alpine hello world container
# For now this is useless, any string can be passed to it
# Sample call: arglib run hello
run.add_argument('run_image', type=str)
# Adds the option to start the container detached
# Sample call: arglib run -d
run.add_argument('-detach', '-d', action='store_true', required=False)
# Get the arguments
args = parser.parse_args()
# Initialize the client
client = docker.from_env()
if args.command == 'pull':
print(f'Pulling {args.image_name} from Dockerhub\n')
pull_image(client, args.image_name)
elif args.command == 'run':
# Get the container flags
detach_flag = args.detach
pull_image(client, 'alpine')
if(detach_flag):
run_detached_hello(client)
else:
run_hello_world(client)
if __name__ == "__main__":
main()