Compose cli option-classes#
When building complex CLI tools, it’s common to reuse and combine sets of arguments across multiple commands or components. Within the argclz system, you can define reusable option classes. These can be composed together through standard Python class inheritance. This enables modular and maintainable CLI definitions.
class IOOptions: # [1]
input_path: str = argument('--input', metavar='FILE', help='Input file')
output_path: str = argument('--output', metavar='FILE', help='Output file')
class LoggingOptions: # [1]
verbose: bool = argument('--verbose', help='Enable verbose logging')
log_level: Literal['info', 'debug', 'warn'] = argument('--log', default='info', help='Log level')
class MyOptions(IOOptions, LoggingOptions): # [2]
# [3]
input_path = as_argument(IOOptions.input_path).with_options(
validator.is_file().is_suffix('.csv'),
required=True,
help='(required) Input file'
)
# [4]
log_level = as_argument(LoggingOptions.log_level).with_options(
choices=['info', 'debug'],
hidden=True
)
# [5]
other_option = argument(...)
reusable options classes, which might be put at different files.
class
MyOptionsinherit arguments fromIOOptionsandLoggingOptions.overwrite
IOOptions.input_pathby adding a file validator that only accept .csv suffix, and settingrequired=Trueoverwrite
LoggingOptions.log_levelby limiting accepted choices forlog_levelonlyinfoordebug, and hiding it from help output.class
MyOptionsspecific arguments.