| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from pyqi.core.interfaces.optparse import (OptparseOption, |
| 4 |
OptparseUsageExample, |
| 5 |
OptparseOption, OptparseResult) |
| 6 |
from pyqi.commands.make_command import CommandConstructor |
| 7 |
|
| 8 |
# If you need access to input or output handlers provided by pyqi, consider |
| 9 |
# importing from the following modules: |
| 10 |
# pyqi.core.interfaces.optparse.input_handler |
| 11 |
# pyqi.core.interfaces.optparse.output_handler |
| 12 |
# pyqi.interfaces.optparse.input_handler |
| 13 |
# pyqi.interfaces.optparse.output_handler |
| 14 |
|
| 15 |
# Examples of how the command can be used from the command line using an |
| 16 |
# optparse interface. |
| 17 |
usage_examples = [ |
| 18 |
OptparseUsageExample(ShortDesc="A short single sentence description of the example", |
| 19 |
LongDesc="A longer, more detailed description", |
| 20 |
Ex="%prog --foo --bar some_file") |
| 21 |
] |
| 22 |
|
| 23 |
# inputs map command line arguments and values onto Parameters. It is possible |
| 24 |
# to define options here that do not exist as parameters, e.g., an output file. |
| 25 |
inputs = [ |
| 26 |
# An example option that has a direct relationship with a Parameter. |
| 27 |
# OptparseOption(Parameter=CommandConstructor.Parameters['name_of_a_parameter'], |
| 28 |
# InputType='existing_filepath', # the optparse type of input |
| 29 |
# InputHandler=None, # Apply a function to the input value to convert it into the type expected by Parameter.DataType |
| 30 |
# ShortName='n', # a parameter short name, can be None |
| 31 |
# # Name='foo', # implied by Parameter. Can be overwritten here if desired |
| 32 |
# # Required=True, # implied by Parameter. Can be promoted by setting True |
| 33 |
# # Help, # implied by Parameter.Description. Can be overwritten here if desired |
| 34 |
# convert_to_dashed_name=True), # whether the Name (either implied by Parameter or defined above) should have underscores converted to dashes when displayed to the user |
| 35 |
# |
| 36 |
# An example option that does not have an associated Parameter. |
| 37 |
# OptparseOption(Parameter=None, |
| 38 |
# InputType='new_filepath', |
| 39 |
# InputHandler=None, # we don't need an InputHandler because this option isn't being converted into a format that a Parameter expects |
| 40 |
# ShortName='o', |
| 41 |
# Name='output-fp', |
| 42 |
# Required=True, |
| 43 |
# Help='output filepath') |
| 44 |
OptparseOption(Parameter=CommandConstructor.Parameters['license'], |
| 45 |
InputType=<type 'str'>, |
| 46 |
InputHandler=None, # must be defined if desired |
| 47 |
ShortName=None), # must be defined if desired |
| 48 |
# Name='license', # implied by Parameter |
| 49 |
# Required=True, # implied by Parameter |
| 50 |
# Help='the license for the Command', # implied by Parameter |
| 51 |
OptparseOption(Parameter=CommandConstructor.Parameters['name'], |
| 52 |
InputType=<type 'str'>, |
| 53 |
InputHandler=None, # must be defined if desired |
| 54 |
ShortName=None), # must be defined if desired |
| 55 |
# Name='name', # implied by Parameter |
| 56 |
# Required=True, # implied by Parameter |
| 57 |
# Help='the name of the Command', # implied by Parameter |
| 58 |
OptparseOption(Parameter=CommandConstructor.Parameters['copyright'], |
| 59 |
InputType=<type 'str'>, |
| 60 |
InputHandler=None, # must be defined if desired |
| 61 |
ShortName=None), # must be defined if desired |
| 62 |
# Name='copyright', # implied by Parameter |
| 63 |
# Required=True, # implied by Parameter |
| 64 |
# Help='the Command copyright', # implied by Parameter |
| 65 |
OptparseOption(Parameter=CommandConstructor.Parameters['author'], |
| 66 |
InputType=<type 'str'>, |
| 67 |
InputHandler=None, # must be defined if desired |
| 68 |
ShortName=None), # must be defined if desired |
| 69 |
# Name='author', # implied by Parameter |
| 70 |
# Required=True, # implied by Parameter |
| 71 |
# Help='the Command author', # implied by Parameter |
| 72 |
OptparseOption(Parameter=CommandConstructor.Parameters['credits'], |
| 73 |
InputType=<type 'str'>, |
| 74 |
InputHandler=None, # must be defined if desired |
| 75 |
ShortName=None), # must be defined if desired |
| 76 |
# Name='credits', # implied by Parameter |
| 77 |
# Required=False, # implied by Parameter |
| 78 |
# Help='comma-separated list of other authors', # implied by Parameter |
| 79 |
OptparseOption(Parameter=CommandConstructor.Parameters['command_version'], |
| 80 |
InputType=<type 'str'>, |
| 81 |
InputHandler=None, # must be defined if desired |
| 82 |
ShortName=None), # must be defined if desired |
| 83 |
# Name='command_version', # implied by Parameter |
| 84 |
# Required=True, # implied by Parameter |
| 85 |
# Help='the Command version', # implied by Parameter |
| 86 |
OptparseOption(Parameter=CommandConstructor.Parameters['email'], |
| 87 |
InputType=<type 'str'>, |
| 88 |
InputHandler=None, # must be defined if desired |
| 89 |
ShortName=None), # must be defined if desired |
| 90 |
# Name='email', # implied by Parameter |
| 91 |
# Required=True, # implied by Parameter |
| 92 |
# Help='maintainer email address', # implied by Parameter |
| 93 |
|
| 94 |
] |
| 95 |
|
| 96 |
# outputs map result keys to output options and handlers. It is not necessary |
| 97 |
# to supply an associated option, but if you do, it must be an option from the |
| 98 |
# inputs list (above). |
| 99 |
outputs = [ |
| 100 |
# An example option that maps to a result key. |
| 101 |
# OptparseResult(ResultKey='some_result', |
| 102 |
# OutputHandler=write_string, # a function applied to the value at ResultKey |
| 103 |
# |
| 104 |
# # the name of the option (defined in inputs, above), whose |
| 105 |
# # value will be made available to OutputHandler. This name |
| 106 |
# # can be either an underscored or dashed version of the |
| 107 |
# # option name (e.g., 'output_fp' or 'output-fp') |
| 108 |
# OptionName='output-fp'), |
| 109 |
# |
| 110 |
# An example option that does not map to a result key. |
| 111 |
# OptparseResult(ResultKey='some_other_result', |
| 112 |
# OutputHandler=print_string) |
| 113 |
] |