Skip to content

Commit

Permalink
Curbed some namespace pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Nov 3, 2014
1 parent befc486 commit 604c647
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion commands/TEMPLATE.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from commands import MutuallyExclusiveGroup, ParseArgument
from commands.parsing import MutuallyExclusiveGroup, ParseArgument

######################################################################
# Parser config
Expand Down
13 changes: 7 additions & 6 deletions commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import os
import importlib

from commands.exceptions import *
from commands.parsing import *
import commands.exceptions
import commands.parsing

commandList = [
'buildcache',
'local'
]

######################################################################
# Helpers

class HelpAction(ArgAction):
class HelpAction(argparse.Action):
"""
argparse action helper for printing the argument usage,
because Python 3.4's argparse is ever-so subtly very broken.
Expand All @@ -31,7 +32,7 @@ def addArguments(group, options, required, topGroup=None):
mutually exclusive group of arguments.
"""
for option in options:
if isinstance(option, MutuallyExclusiveGroup):
if isinstance(option, parsing.MutuallyExclusiveGroup):
exGrp = (topGroup or group).add_mutually_exclusive_group()
addArguments(exGrp, option.arguments, required, topGroup=group)
else:
Expand Down Expand Up @@ -115,13 +116,13 @@ def parse(self, argv):
### the user requests usage.
cmdName = argv[1].lower()
if cmdName not in commandList:
raise CommandLineError("Unrecognized command, '{}'".format(cmdName), self.usage(argv))
raise exceptions.CommandLineError("Unrecognized command, '{}'".format(cmdName), self.usage(argv))

cmdModule = import_module(cmdName)

class ArgParser(argparse.ArgumentParser):
def error(self, message):
raise CommandLineError(message, self.format_usage())
raise exceptions.CommandLineError(message, self.format_usage())

parser = ArgParser(
description="TradeDangerous: "+cmdName,
Expand Down
2 changes: 1 addition & 1 deletion commands/local_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from commands import MutuallyExclusiveGroup, ParseArgument
from commands.parsing import MutuallyExclusiveGroup, ParseArgument
import math

######################################################################
Expand Down
2 changes: 1 addition & 1 deletion commands/nav_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from commands import MutuallyExclusiveGroup, ParseArgument
from commands.parsing import MutuallyExclusiveGroup, ParseArgument

######################################################################
# Parser config
Expand Down
3 changes: 0 additions & 3 deletions commands/parsing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from commands.exceptions import UsageError
from argparse import Action as ArgAction

######################################################################
# Parsing Helpers

Expand Down

0 comments on commit 604c647

Please sign in to comment.