Commit 356aa6ba authored by Marco Mariani's avatar Marco Mariani

completed console argument parsing

parent 1c5fcb24
...@@ -23,9 +23,22 @@ class ConsoleCommand(ClientConfigCommand): ...@@ -23,9 +23,22 @@ class ConsoleCommand(ClientConfigCommand):
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_parser(self, prog_name):
ap = super(ConsoleCommand, self).get_parser(prog_name)
ap.add_argument('-u', '--master_url',
help='Url of SlapOS Master to use')
ap.add_argument('-k', '--key_file',
help='SSL Authorisation key file')
ap.add_argument('-c', '--cert_file',
help='SSL Authorisation certificate file')
return ap
def take_action(self, args): def take_action(self, args):
configuration_parser = self.fetch_config(args) configuration_parser = self.fetch_config(args)
config = ClientConfig(args, configuration_parser) config = ClientConfig(args, configuration_parser)
local = init(config) local = init(config)
do_console(local) do_console(local)
...@@ -30,48 +30,12 @@ ...@@ -30,48 +30,12 @@
import argparse import argparse
import ConfigParser import ConfigParser
import pprint import pprint
from optparse import OptionParser, Option
import os import os
from slapos.slap import ResourceNotReady from slapos.slap import ResourceNotReady
import slapos.slap.slap import slapos.slap.slap
import sys import sys
import atexit import atexit
class Parser(OptionParser):
"""
Parse all arguments.
"""
def __init__(self, usage=None, version=None):
"""
Initialize all options possibles.
"""
OptionParser.__init__(self, usage=usage, version=version,
option_list=[
Option("-u", "--master_url",
default=None,
action="store",
help="Url of SlapOS Master to use."),
Option("-k", "--key_file",
action="store",
help="SSL Authorisation key file."),
Option("-c", "--cert_file",
action="store",
help="SSL Authorisation certificate file.")
])
def check_args(self):
"""
Check arguments
"""
(options, args) = self.parse_args()
if len(args) == 0:
self.error("Incorrect number of arguments")
elif not os.path.isfile(args[0]):
self.error("%s: Not found or not a regular file." % args[0])
# Return options and only first element of args since there is only one.
return options, args[0]
def argToDict(element): def argToDict(element):
""" """
...@@ -323,8 +287,32 @@ examples : ...@@ -323,8 +287,32 @@ examples :
>>> supply(kvm, "mycomputer") >>> supply(kvm, "mycomputer")
>>> # Fetch instance informations on already launched instance >>> # Fetch instance informations on already launched instance
>>> request(kvm, "myuniquekvm").getConnectionParameter("url")""" % sys.argv[0] >>> request(kvm, "myuniquekvm").getConnectionParameter("url")""" % sys.argv[0]
options, configuration_file_path = Parser(usage=usage).check_args()
config = ClientConfig(options, get_config_parser(configuration_file_path))
ap = argparse.ArgumentParser(usage=usage)
ap.add_argument('-u', '--master_url',
default=None,
action="store",
help='Url of SlapOS Master to use.')
ap.add_argument('-k', '--key_file',
action="store",
help="SSL Authorisation key file.")
ap.add_argument('-c', '--cert_file',
action="store",
help="SSL Authorisation certificate file.")
ap.add_argument('configuration_file',
help='path to slapos.cfg')
options = ap.parse_args()
if not os.path.isfile(options.configuration_file):
ap.error("%s: Not found or not a regular file." % options.configuration_file)
config = ClientConfig(options, get_config_parser(options.configuration_file))
local = init(config) local = init(config)
do_console(local) do_console(local)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment