summaryrefslogtreecommitdiff
path: root/xnt
diff options
context:
space:
mode:
authorkennyballou <kballou@onyx.boisestate.edu>2013-01-10 10:22:19 -0700
committerkballou <kballou@onyx.boisestate.edu>2013-01-10 10:22:19 -0700
commit95570153e73ba662ecd8d2adbd76dc509f166122 (patch)
treeda56595c5fefa1970469778c682077c56789793c /xnt
parent3739011c6173f4048fbbd94c0411dc103bf32ce5 (diff)
downloadxnt-95570153e73ba662ecd8d2adbd76dc509f166122.tar.gz
xnt-95570153e73ba662ecd8d2adbd76dc509f166122.tar.xz
Refactor version and usage methods
Both of these methods printed directly to stdout, which can't be easily tested. To make things easier, these methods should return what would otherwise be printed, so that testing modules can easily check the return value
Diffstat (limited to 'xnt')
-rw-r--r--xnt/xenant.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/xnt/xenant.py b/xnt/xenant.py
index 96102bc..a4cffaf 100644
--- a/xnt/xenant.py
+++ b/xnt/xenant.py
@@ -26,11 +26,11 @@ logger = logging.Logger(name=__name__)
logger.addHandler(logging.StreamHandler())
def usageAction():
- printUsage()
+ print(usage());
sys.exit(0)
def versionAction():
- printVersion()
+ print(version())
sys.exit(0)
def verboseAction():
@@ -69,27 +69,31 @@ def invokeBuild(build, targetName):
except:
logger.error(sys.exc_info()[1].message)
-def printUsage():
+def usage():
import xnt
- print(xnt.__version__)
- print(xnt.__license__)
- print("Usage:\txnt [options] [target]")
- print("Where [target] is a target in your ``build.py`` file")
- print(" And [options] is one of the falling:")
- print("\t-v: print verbose information about Xnt's running")
- print("\t--usage: Print this message")
- print("In addition to targets defined by your ``build.py`` file")
- print("\t``list-targets`` can be used in place of [targets] to")
- print("\t\tlist targets and docstrings defined in your ``build.py`` file")
- print("\tIf no [target] is provided, Xnt will try the target: ``default``")
- print("\n")
-
-def printVersion():
+ endl = os.linesep
+ usageText = \
+ xnt.__version__ + endl + \
+ xnt.__license__ + endl + \
+ "Usage:\txnt [options] [target]" + endl + \
+ "Where [target] is a target in your ``build.py`` file" + endl + \
+ " And [options] is one of the falling:" + endl + \
+ "\t-v: print verbose information about Xnt's running" + endl + \
+ "\t--usage: Print this message" + endl + \
+ "In addition to targets defined by your ``build.py`` file" + endl + \
+ "\t``list-targets`` can be used in place of [targets] to" + endl + \
+ "\t\tlist targets and docstrings defined in your ``build.py`` file" + \
+ endl + \
+ "\tIf no [target] is provided, Xnt will try the target: ``default``" \
+ + endl
+ return usageText
+
+def version():
import xnt
- print(xnt.__version__)
+ return xnt.__version__
def printTargets(build):
- printVersion()
+ print(version())
print("\n")
try:
for f in dir(build):