OLD | NEW |
(Empty) | |
| 1 # -*- coding: utf-8 -*- |
| 2 """The language CLI arguments helper.""" |
| 3 |
| 4 from plaso.cli import tools |
| 5 from plaso.cli.helpers import interface |
| 6 from plaso.cli.helpers import manager |
| 7 from plaso.lib import errors |
| 8 |
| 9 |
| 10 class LanguageArgumentsHelper(interface.ArgumentsHelper): |
| 11 """Language CLI arguments helper.""" |
| 12 |
| 13 NAME = u'language' |
| 14 DESCRIPTION = u'Language command line arguments.' |
| 15 |
| 16 @classmethod |
| 17 def AddArguments(cls, argument_group): |
| 18 """Adds command line arguments to an argument group. |
| 19 |
| 20 This function takes an argument parser or an argument group object and adds |
| 21 to it all the command line arguments this helper supports. |
| 22 |
| 23 Args: |
| 24 argument_group (argparse._ArgumentGroup|argparse.ArgumentParser): |
| 25 argparse group. |
| 26 """ |
| 27 argument_group.add_argument( |
| 28 u'--language', metavar=u'LANGUAGE', dest=u'preferred_language', |
| 29 default=u'en-US', type=str, help=( |
| 30 u'The preferred language identifier for Windows Event Log message ' |
| 31 u'strings. Use "--language list" to see a list of available ' |
| 32 u'language identifiers. Note that formatting will fall back on ' |
| 33 u'en-US (LCID 0x0409) if the preferred language is not available ' |
| 34 u'in the database of message string templates.')) |
| 35 |
| 36 @classmethod |
| 37 def ParseOptions(cls, options, configuration_object): |
| 38 """Parses and validates options. |
| 39 |
| 40 Args: |
| 41 options (argparse.Namespace): parser options. |
| 42 configuration_object (CLITool): object to be configured by the argument |
| 43 helper. |
| 44 |
| 45 Raises: |
| 46 BadConfigObject: when the configuration object is of the wrong type. |
| 47 """ |
| 48 if not isinstance(configuration_object, tools.CLITool): |
| 49 raise errors.BadConfigObject( |
| 50 u'Configuration object is not an instance of CLITool') |
| 51 |
| 52 preferred_language = cls._ParseStringOption( |
| 53 options, u'preferred_language', default_value=u'en-US') |
| 54 |
| 55 setattr(configuration_object, u'_preferred_language', preferred_language) |
| 56 |
| 57 |
| 58 manager.ArgumentHelperManager.RegisterHelper(LanguageArgumentsHelper) |
OLD | NEW |