| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4270a7b commit 71c419d
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,17 +64,19 @@ def parse(args, extras=None, ignore_stdin=False): | |||
| 64 | 64 | be a tuple of (title, description, options) | |
| 65 | 65 | title: The title for the option group | |
| 66 | 66 | description: A full description of the option group | |
| 67 | - options: A list of optparse.Option objects to be added to the | ||
| 68 | - group | ||
| 67 | + callback: A callback that adds options to the option group | ||
| 69 | 68 | ||
| 70 | 69 | e.g.: | |
| 71 | 70 | ||
| 71 | + def callback(group): | ||
| 72 | + group.add_option('-f', action='store_true', dest='f', help='Explode') | ||
| 73 | + group.add_option('-l', action='store_true', dest='l', help='Love') | ||
| 74 | + | ||
| 72 | 75 | parse( | |
| 73 | 76 | ['-i', '-m', 'foo.py'], | |
| 74 | 77 | ('Front end-specific options', | |
| 75 | 78 | 'A full description of what these options are for', | |
| 76 | - [optparse.Option('-f', action='store_true', dest='f', help='Explode'), | ||
| 77 | - optparse.Option('-l', action='store_true', dest='l', help='Love')])) | ||
| 79 | + callback)) | ||
| 78 | 80 | ||
| 79 | 81 | ||
| 80 | 82 | Return a tuple of (config, options, exec_args) wherein "config" is the | |
@@ -125,8 +127,7 @@ def parse(args, extras=None, ignore_stdin=False): | |||
| 125 | 127 | ||
| 126 | 128 | if extras is not None: | |
| 127 | 129 | extras_group = OptionGroup(parser, extras[0], extras[1]) | |
| 128 | - for option in extras[2]: | ||
| 129 | - extras_group.add_option(option) | ||
| 130 | + extras[2](extras_group) | ||
| 130 | 131 | parser.add_option_group(extras_group) | |
| 131 | 132 | ||
| 132 | 133 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | import collections | |
| 2 | 2 | import logging | |
| 3 | 3 | import sys | |
| 4 | - from optparse import Option | ||
| 5 | 4 | ||
| 6 | 5 | import curtsies | |
| 7 | 6 | import curtsies.window | |
@@ -134,25 +133,26 @@ def main(args=None, locals_=None, banner=None, welcome_message=None): | |||
| 134 | 133 | """ | |
| 135 | 134 | translations.init() | |
| 136 | 135 | ||
| 136 | + def curtsies_arguments(parser): | ||
| 137 | + parser.add_argument( | ||
| 138 | + "--log", | ||
| 139 | + "-L", | ||
| 140 | + action="count", | ||
| 141 | + help=_("log debug messages to bpython.log"), | ||
| 142 | + ) | ||
| 143 | + parser.add_argument( | ||
| 144 | + "--paste", | ||
| 145 | + "-p", | ||
| 146 | + action="store_true", | ||
| 147 | + help=_("start by pasting lines of a file into session"), | ||
| 148 | + ) | ||
| 149 | + | ||
| 137 | 150 | config, options, exec_args = bpargs.parse( | |
| 138 | 151 | args, | |
| 139 | 152 | ( | |
| 140 | 153 | "curtsies options", | |
| 141 | 154 | None, | |
| 142 | - [ | ||
| 143 | - Option( | ||
| 144 | - "--log", | ||
| 145 | - "-L", | ||
| 146 | - action="count", | ||
| 147 | - help=_("log debug messages to bpython.log"), | ||
| 148 | - ), | ||
| 149 | - Option( | ||
| 150 | - "--paste", | ||
| 151 | - "-p", | ||
| 152 | - action="store_true", | ||
| 153 | - help=_("start by pasting lines of a file into session"), | ||
| 154 | - ), | ||
| 155 | - ], | ||
| 155 | + curtsies_arguments, | ||
| 156 | 156 | ), | |
| 157 | 157 | ) | |
| 158 | 158 | if options.log is None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,6 @@ | |||
| 37 | 37 | import time | |
| 38 | 38 | import locale | |
| 39 | 39 | import signal | |
| 40 | - from optparse import Option | ||
| 41 | 40 | ||
| 42 | 41 | from pygments.token import Token | |
| 43 | 42 | ||
@@ -1120,47 +1119,48 @@ def tab(self, back=False): | |||
| 1120 | 1119 | def main(args=None, locals_=None, banner=None): | |
| 1121 | 1120 | translations.init() | |
| 1122 | 1121 | ||
| 1122 | + def options_callback(group): | ||
| 1123 | + group.add_option( | ||
| 1124 | + "--twisted", | ||
| 1125 | + "-T", | ||
| 1126 | + action="store_true", | ||
| 1127 | + help=_("Run twisted reactor."), | ||
| 1128 | + ) | ||
| 1129 | + group.add_option( | ||
| 1130 | + "--reactor", | ||
| 1131 | + "-r", | ||
| 1132 | + help=_( | ||
| 1133 | + "Select specific reactor (see --help-reactors). " | ||
| 1134 | + "Implies --twisted." | ||
| 1135 | + ), | ||
| 1136 | + ) | ||
| 1137 | + group.add_option( | ||
| 1138 | + "--help-reactors", | ||
| 1139 | + action="store_true", | ||
| 1140 | + help=_("List available reactors for -r."), | ||
| 1141 | + ) | ||
| 1142 | + group.add_option( | ||
| 1143 | + "--plugin", | ||
| 1144 | + "-p", | ||
| 1145 | + help=_( | ||
| 1146 | + "twistd plugin to run (use twistd for a list). " | ||
| 1147 | + 'Use "--" to pass further options to the plugin.' | ||
| 1148 | + ), | ||
| 1149 | + ) | ||
| 1150 | + group.add_option( | ||
| 1151 | + "--server", | ||
| 1152 | + "-s", | ||
| 1153 | + type="int", | ||
| 1154 | + help=_("Port to run an eval server on (forces Twisted)."), | ||
| 1155 | + ) | ||
| 1156 | + | ||
| 1123 | 1157 | # TODO: maybe support displays other than raw_display? | |
| 1124 | 1158 | config, options, exec_args = bpargs.parse( | |
| 1125 | 1159 | args, | |
| 1126 | 1160 | ( | |
| 1127 | 1161 | "Urwid options", | |
| 1128 | 1162 | None, | |
| 1129 | - [ | ||
| 1130 | - Option( | ||
| 1131 | - "--twisted", | ||
| 1132 | - "-T", | ||
| 1133 | - action="store_true", | ||
| 1134 | - help=_("Run twisted reactor."), | ||
| 1135 | - ), | ||
| 1136 | - Option( | ||
| 1137 | - "--reactor", | ||
| 1138 | - "-r", | ||
| 1139 | - help=_( | ||
| 1140 | - "Select specific reactor (see --help-reactors). " | ||
| 1141 | - "Implies --twisted." | ||
| 1142 | - ), | ||
| 1143 | - ), | ||
| 1144 | - Option( | ||
| 1145 | - "--help-reactors", | ||
| 1146 | - action="store_true", | ||
| 1147 | - help=_("List available reactors for -r."), | ||
| 1148 | - ), | ||
| 1149 | - Option( | ||
| 1150 | - "--plugin", | ||
| 1151 | - "-p", | ||
| 1152 | - help=_( | ||
| 1153 | - "twistd plugin to run (use twistd for a list). " | ||
| 1154 | - 'Use "--" to pass further options to the plugin.' | ||
| 1155 | - ), | ||
| 1156 | - ), | ||
| 1157 | - Option( | ||
| 1158 | - "--server", | ||
| 1159 | - "-s", | ||
| 1160 | - type="int", | ||
| 1161 | - help=_("Port to run an eval server on (forces Twisted)."), | ||
| 1162 | - ), | ||
| 1163 | - ], | ||
| 1163 | + options_callback, | ||
| 1164 | 1164 | ), | |
| 1165 | 1165 | ) | |
| 1166 | 1166 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments