diff --git a/README.md b/README.md index 5d234b1..5669b94 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ optional arguments: ## explorationtools.py ## ``` -usage: explorationtools.py [-h] {bodycount,distancebetween} ... +usage: explorationtools.py [-h] {bodycount,distancebetween,findCommander} ... A collection of tools useful for exploration. @@ -31,7 +31,7 @@ optional arguments: -h, --help show this help message and exit subcommands: - {bodycount,distancebetween} + {bodycount,distancebetween,findCommander} sub-command help bodycount Returns the number of bodies in a system. Will exit with code 1 on server error and code 2 if the system @@ -39,6 +39,9 @@ subcommands: distancebetween Calculates the distance between two systems. Will exit with code 1 on server error and code 2 if (one of) the systems could not be found on EDSM. + findCommander Attempts to find a CMDR’s last known position. Will + exit with code 1 on server error and code 2 if the + CMDR could not be found on EDSM. ``` ``` @@ -60,3 +63,13 @@ positional arguments: optional arguments: -h, --help show this help message and exit ``` + +``` +usage: explorationtools.py findCommander [-h] name + +positional arguments: + name + +optional arguments: + -h, --help show this help message and exit +``` diff --git a/explorationtools.py b/explorationtools.py index e5928cc..180e5a5 100755 --- a/explorationtools.py +++ b/explorationtools.py @@ -25,6 +25,19 @@ def distanceBetween(system1, system2): + (coords1['z']-coords2['z'])**2 ),0))) sys.exit(0) +def findCommander(name): + try: + currentSystem = Commander(name).currentSystem + except ServerError as e: + print(e) + sys.exit(1) + except NotFoundError as e: + print(e) + sys.exit(2) + else: + print(currentSystem) + sys.exit(0) + def getBodyCount(system): try: bodyCount = System(system).bodyCount @@ -56,6 +69,11 @@ parser_distance = subparsers.add_parser("distancebetween", + "on EDSM.") parser_distance.add_argument("system", nargs=2) +parser_find = subparsers.add_parser("findCommander", + help="Attempts to find a CMDR’s last known position. Will exit with code 1 " + + "on server error and code 2 if the CMDR could not be found on EDSM.") +parser_find.add_argument("name") + argcomplete.autocomplete(parser) args = parser.parse_args() @@ -65,3 +83,5 @@ if args.subCommand == "bodycount": getBodyCount(args.system[0]) elif args.subCommand == "distancebetween": distanceBetween(args.system[0], args.system[1]) +elif args.subCommand == "findCommander": + findCommander(args.name) diff --git a/generate_docs.sh b/generate_docs.sh index 3f09a78..f914ca9 100644 --- a/generate_docs.sh +++ b/generate_docs.sh @@ -27,8 +27,12 @@ cat >> README.md << EOF \`\`\` EOF ./explorationtools.py distancebetween -h >> README.md +cat >> README.md << EOF +\`\`\` - +\`\`\` +EOF +./explorationtools.py findCommander -h >> README.md cat >> README.md << EOF \`\`\` EOF