Determine whether a function is an optional handler for a I{flag} or an I{option}. A I{flag} handler takes no additional arguments. It is used to handle command-line arguments like I{--nodaemon}. An I{option} handler takes one argument. It is used to handle command-line
(method, name=None)
| 972 | |
| 973 | |
| 974 | def flagFunction(method, name=None): |
| 975 | """ |
| 976 | Determine whether a function is an optional handler for a I{flag} or an |
| 977 | I{option}. |
| 978 | |
| 979 | A I{flag} handler takes no additional arguments. It is used to handle |
| 980 | command-line arguments like I{--nodaemon}. |
| 981 | |
| 982 | An I{option} handler takes one argument. It is used to handle command-line |
| 983 | arguments like I{--path=/foo/bar}. |
| 984 | |
| 985 | @param method: The bound method object to inspect. |
| 986 | |
| 987 | @param name: The name of the option for which the function is a handle. |
| 988 | @type name: L{str} |
| 989 | |
| 990 | @raise UsageError: If the method takes more than one argument. |
| 991 | |
| 992 | @return: If the method is a flag handler, return C{True}. Otherwise return |
| 993 | C{False}. |
| 994 | """ |
| 995 | reqArgs = len(inspect.signature(method).parameters) |
| 996 | if reqArgs > 1: |
| 997 | raise UsageError("Invalid Option function for %s" % (name or method.__name__)) |
| 998 | if reqArgs == 1: |
| 999 | return False |
| 1000 | return True |
| 1001 | |
| 1002 | |
| 1003 | def portCoerce(value): |
no test coverage detected