-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get argparser to return help string instead of printing (#30)
* NonPrintingParser raises PrintingException instead of printing * Switch to using NonPrintingParser instead of ArgumentParser * Test that help/error messages return strings instead of printing * Check for raising PrintingException instead of SystemExit * Python 2/3 compatibility for strings
- Loading branch information
Showing
5 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import argparse | ||
|
||
from .error import PrintingException | ||
|
||
|
||
class NonPrintingParser(argparse.ArgumentParser): | ||
"""ArgumentParser that will return help and error strings instead of printing.""" | ||
|
||
def print_usage(self, file=None): | ||
raise PrintingException(self.format_usage()) | ||
|
||
def print_help(self, file=None): | ||
raise PrintingException(self.format_help()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
class APIException(Exception): | ||
def __init__(self, *args, **kwargs): | ||
super(APIException, self).__init__(*args, **kwargs) | ||
|
||
|
||
class PrintingException(Exception): | ||
"""NonPrintingParser will raise this to notify CLI to exit and transfer help message (needed for slackbot).""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(PrintingException, self).__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters