#   Copyright 2012-2013 OpenStack Foundation
#
#   Licensed under the Apache License, Version 2.0 (the "License"); you may
#   not use this file except in compliance with the License. You may obtain
#   a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#   License for the specific language governing permissions and limitations
#   under the License.
#

"""Command-line interface to Configuration Discovery


    TODO(zns): testing, refactoring, etc...  just using this to demonstrate
    functionality

"""

from __future__ import print_function

import sys

from satori import discovery


def main(argv=sys.argv[1:]):
    """Demonstrating usage."""
    if (not isinstance(argv, list)) or len(argv) < 1:
        print("No address supplied. Usage: satori [address | name | url]")
        return -1

    if '-h' in argv or '--help' in argv:
        print("Usage: satori [address | name | url]")
        return 0

    results = discovery.run(argv[0])
    output_results(argv[0], results)
    return 0


def output_results(discovered_target, results):
    """Print results in CLI format."""
    address = results['address']
    print(u"Address:\n\t%s resolves to IPv4 address %s" % (
          discovered_target, address))
    if 'host' in results:
        host = results['host']
        print(u"Host:\n\t%s (%s) is hosted on a %s" % (
              address, discovered_target, host['type']))

        print(u"\tInstance Information:")
        print(u"\t\tURI: %s" % host['uri'])
        print(u"\t\tName: %s" % host['name'])
        print(u"\t\tID: %s" % host['id'])

        print(u"\tip-addresses:")
        addresses = host.get('addresses') or {}
        for name, address_list in addresses.iteritems():
            print(u"\t\t%s:" % name)
            for server_address in address_list:
                print(u"\t\t\t%s:" % server_address['addr'])
    else:
        print(u"Host not found")


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))

@@ -662,104 +662,113 @@
 very
-%0A%0A%0A    TODO(zns): testing, refactoring, etc...  just using this to demonstrate%0A    functionality
+.%0A%0AAccept a network location, run through the discovery process and report the%0Afindings back to the user.
 %0A%0A%22%22
@@ -809,16 +809,32 @@
 nction%0A%0A
+import argparse%0A
 import s
@@ -881,319 +881,338 @@
 ain(
-argv=sys.argv%5B1:%5D):%0A    %22%22%22Demonstrating usage.%22%22%22%0A    if (not isinstance(argv, list)) or len(argv) %3C 1:%0A        print(%22No address supplied. Usage: satori %5Baddress %7C name %7C url%5D%22)%0A        return -1%0A%0A    if '-h' in argv or '--help' in argv:%0A        print(%22Usage: satori %5Baddress %7C name %7C url%5D%22)
+):%0A    %22%22%22Discover an existing configuration for a network location.%22%22%22%0A    parser = argparse.ArgumentParser(description='Configuration discovery.')%0A    parser.add_argument(%0A        'netloc',%0A        help='Network location. E.g. https://domain.com, sub.domain.com, or '%0A             '4.3.2.1'
 %0A    
+)%0A%0A
     
-return 0%0A
+args = parser.parse_args()
 %0A   
@@ -1239,20 +1239,24 @@
 .run(arg
-v%5B0%5D
+s.netloc
 )%0A    ou
@@ -1275,12 +1275,16 @@
 (arg
-v%5B0%5D
+s.netloc
 , re
@@ -2249,19 +2249,7 @@
 ain(
-sys.argv%5B1:%5D
 ))%0A

Use argparse, implements poc-commandline-parsing