Add argument parsing
This commit is contained in:
parent
efbb9d122c
commit
f2e1ab11af
32
dox/cmd.py
32
dox/cmd.py
@ -13,11 +13,37 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
import dox.locations
|
import dox.locations
|
||||||
import dox.payloads
|
import dox.payloads
|
||||||
|
import dox.runner
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
location = dox.locations.Location()
|
parser = argparse.ArgumentParser(description='Run tests in docker.')
|
||||||
payload = dox.payloads.Payload()
|
parser.add_argument(dest='extra_args', nargs='*',
|
||||||
return location.run(payload)
|
help='args to append to command, or command to run'
|
||||||
|
' if -c is given')
|
||||||
|
parser.add_argument('-i', '--image', dest='image',
|
||||||
|
help='Base image to use')
|
||||||
|
parser.add_argument('-c', '--command', dest='command', default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='Treat arguments as the entire command to run')
|
||||||
|
parser.add_argument('-r', '--rebuild', dest='rebuild', default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='Rebuild the test image')
|
||||||
|
parser.add_argument('--rebuild-all', dest='rebuild_all', default=False,
|
||||||
|
action='store_true', help='Rebuild all images')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
image = args.image
|
||||||
|
if args.image is None:
|
||||||
|
image = dox.locations.get_image()
|
||||||
|
if args.command:
|
||||||
|
command = " ".join(args.extra_args)
|
||||||
|
else:
|
||||||
|
command = dox.payloads.Payload()
|
||||||
|
if args.extra_args:
|
||||||
|
command.append(args.extra_args)
|
||||||
|
return dox.runner.Runner(args).run(image, command)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'get_image',
|
'get_image',
|
||||||
'Location',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
import dox.config.dockerfile
|
import dox.config.dockerfile
|
||||||
@ -41,13 +40,3 @@ def get_image():
|
|||||||
elif tox_ini.exists():
|
elif tox_ini.exists():
|
||||||
image = tox_ini.get_image(image)
|
image = tox_ini.get_image(image)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
class Location(object):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.image = get_image()
|
|
||||||
|
|
||||||
def run(self, payload):
|
|
||||||
print("Going to run {0} in {1}".format(
|
|
||||||
payload, self.image))
|
|
||||||
|
@ -41,8 +41,12 @@ class Payload(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.payload = get_payload()
|
self.payload = get_payload()
|
||||||
|
self.args = []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if hasattr(self.payload, 'append'):
|
if hasattr(self.payload, 'append'):
|
||||||
return "\n".join(self.payload)
|
return "\n".join(self.payload)
|
||||||
return self.payload
|
return self.payload + ' ' + ' '.join(self.args)
|
||||||
|
|
||||||
|
def append(self, args):
|
||||||
|
self.args = args
|
||||||
|
@ -38,8 +38,8 @@ class TestPayloads(base.TestCase):
|
|||||||
('dox_yaml_ignore_others', dict(
|
('dox_yaml_ignore_others', dict(
|
||||||
dox_yaml=True, tox_ini=True, travis_yaml=True,
|
dox_yaml=True, tox_ini=True, travis_yaml=True,
|
||||||
dox_value="testr run", tox_value="setup.py test",
|
dox_value="testr run", tox_value="setup.py test",
|
||||||
travis_value="gem test"
|
travis_value="gem test",
|
||||||
, payload="testr run")),
|
payload="testr run")),
|
||||||
('tox_ini', dict(
|
('tox_ini', dict(
|
||||||
dox_yaml=False, tox_ini=True, travis_yaml=False,
|
dox_yaml=False, tox_ini=True, travis_yaml=False,
|
||||||
dox_value=None, tox_value="setup.py test", travis_value=None,
|
dox_value=None, tox_value="setup.py test", travis_value=None,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pbr>=0.5.21,<1.0
|
pbr>=0.5.21,<1.0
|
||||||
|
|
||||||
|
argparse
|
||||||
PyYAML
|
PyYAML
|
||||||
sh
|
sh
|
||||||
|
Loading…
Reference in New Issue
Block a user