MCPcopy
hub / github.com/pallets/click / OptParseCommand

Class OptParseCommand

tests/test_commands.py:151–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149 pass
150
151 class OptParseCommand(click.Command):
152 def __init__(self, name, parser, callback):
153 super().__init__(name)
154 self.parser = parser
155 self.callback = callback
156
157 def parse_args(self, ctx, args):
158 try:
159 opts, args = parser.parse_args(args)
160 except Exception as e:
161 ctx.fail(str(e))
162 ctx.args = args
163 ctx.params = vars(opts)
164
165 def get_usage(self, ctx):
166 return self.parser.get_usage()
167
168 def get_help(self, ctx):
169 return self.parser.format_help()
170
171 def invoke(self, ctx):
172 ctx.invoke(self.callback, ctx.args, **ctx.params)
173
174 parser = optparse.OptionParser(usage="Usage: foo test [OPTIONS]")
175 parser.add_option(

Callers 1

test_custom_parserFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_custom_parserFunction · 0.68