-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patharguments_parser.py
138 lines (124 loc) · 4.58 KB
/
arguments_parser.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-
#
# Containers Testing Framework command line interface
# Copyright (C) 2015 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
class ArgumentsParser(object):
""" Class for processing data from commandline """
def __init__(self, args=None):
""" parse arguments """
self.parser = argparse.ArgumentParser(
description='CLI for running Containers Testing Framework')
self.subparsers = self.parser.add_subparsers(dest="cli_action")
self.add_args()
self.add_remote_subparser()
self.add_init_subparser()
self.add_run_subparser()
self.add_update_subparser()
self.args = self.parser.parse_args(args)
def add_remote_add_subparser(self, subparser):
subparser.add_argument(
dest='remote_type',
choices=['steps', 'features'])
subparser.add_argument(
dest='url',
help='module url')
subparser.add_argument(
"--project",
dest='project',
help="name of test project")
def add_remote_remove_subparser(self, subparser):
subparser.add_argument(
dest='name')
def add_remote_subparser(self):
remote_subparser = self.subparsers.add_parser(
'remote', help='addidng/removing test suites')
remote_oper_subparser = remote_subparser.add_subparsers(
dest='remote_action')
self.add_remote_add_subparser(remote_oper_subparser.add_parser(
'add', help='add remote repository'))
self.add_remote_remove_subparser(remote_oper_subparser.add_parser(
'remove', help='remove remote repository'))
remote_oper_subparser.add_parser('list', help='list remote repositories')
def add_run_subparser(self):
run_subparser = self.subparsers.add_parser(
'run', help="run test suite - default")
run_subparser.add_argument(
"-c",
"--cli-config",
default=None,
dest='cli_config_path',
help="Path to CLI configuration file" +
"(By default use only CLI arguments and default values)"
)
run_subparser.add_argument(
"-t",
"--tests-config",
default=None,
dest='tests_config_path',
help="Path to tests configuration file. By default it will be searched for in test/ dir"
)
run_subparser.add_argument(
"-d",
"--behave-data",
action='append',
default=None,
dest='behave_data',
help="A way to set behave userdata"
)
run_subparser.add_argument(
"-b",
"--behave-tags",
action='append',
default=None,
dest='behave_tags',
help="A way to set behave test tags"
)
run_subparser.add_argument(
"-j",
"--junit",
default=None,
dest='junit',
help="Junit folder to store results. If not passed junit reports will not be generated"
)
run_subparser.add_argument(
"-o",
"--behave-opts",
action='append',
default=None,
dest='behave_opts',
help="Pass other arguments to behave"
)
def add_update_subparser(self):
self.subparsers.add_parser('update', help="update suites")
def add_init_subparser(self):
self.subparsers.add_parser('init', help="update suites")
def add_args(self):
self.parser.add_argument(
"-v",
"--verbose",
default=False,
action="store_true",
help="Output is more verbose (recommended)"
)
def __getattr__(self, name):
try:
return getattr(self.args, name)
except AttributeError:
try:
return object.__getattribute__(self, name)
except AttributeError:
return None