def DeclareKeyFlags(flag_values=FLAGS): """Declares a few key flags.""" for flag_name in DECLARED_KEY_FLAGS: gflags.DECLARE_key_flag(flag_name, flag_values=flag_values)
def testWriteHelpInXMLFormat(self): fv = gflags.FlagValues() # Since these flags are defined by the top module, they are all key. gflags.DEFINE_integer('index', 17, 'An integer flag', flag_values=fv) gflags.DEFINE_integer('nb_iters', 17, 'An integer flag', lower_bound=5, upper_bound=27, flag_values=fv) gflags.DEFINE_string('file_path', '/path/to/my/dir', 'A test string flag.', flag_values=fv) gflags.DEFINE_boolean('use_hack', False, 'Use performance hack', flag_values=fv) gflags.DEFINE_enum('cc_version', 'stable', ['stable', 'experimental'], 'Compiler version to use.', flag_values=fv) gflags.DEFINE_list('files', 'a.cc,a.h,archive/old.zip', 'Files to process.', flag_values=fv) gflags.DEFINE_list('allow_users', ['alice', 'bob'], 'Users with access.', flag_values=fv) gflags.DEFINE_spaceseplist('dirs', 'src libs bins', 'Directories to create.', flag_values=fv) gflags.DEFINE_multistring('to_delete', ['a.cc', 'b.h'], 'Files to delete', flag_values=fv) gflags.DEFINE_multi_int('cols', [5, 7, 23], 'Columns to select', flag_values=fv) # Define a few flags in a different module. module_bar.DefineFlags(flag_values=fv) # And declare only a few of them to be key. This way, we have # different kinds of flags, defined in different modules, and not # all of them are key flags. gflags.DECLARE_key_flag('tmod_bar_z', flag_values=fv) gflags.DECLARE_key_flag('tmod_bar_u', flag_values=fv) # Generate flag help in XML format in the StringIO sio. sio = StringIO.StringIO() fv.WriteHelpInXMLFormat(sio) # Check that we got the expected result. expected_output_template = EXPECTED_HELP_XML_START main_module_name = gflags._GetMainModule() module_bar_name = module_bar.__name__ if main_module_name < module_bar_name: expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MAIN_MODULE expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MODULE_BAR else: expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MODULE_BAR expected_output_template += EXPECTED_HELP_XML_FOR_FLAGS_FROM_MAIN_MODULE expected_output_template += EXPECTED_HELP_XML_END # XML representation of the whitespace list separators. whitespace_separators = _ListSeparatorsInXMLFormat(string.whitespace, indent=' ') expected_output = (expected_output_template % { 'usage_doc': sys.modules['__main__'].__doc__, 'main_module_name': main_module_name, 'module_bar_name': module_bar_name, 'whitespace_separators': whitespace_separators }) actual_output = sio.getvalue() self.assertMultiLineEqual(actual_output, expected_output) # Also check that our result is valid XML. minidom.parseString # throws an xml.parsers.expat.ExpatError in case of an error. xml.dom.minidom.parseString(actual_output)
flags.DEFINE_string( 'output_file', None, 'An output file path to contain the archive for the generated library.' ' The contents of the file are determined by the output_format parameter') flags.DEFINE_enum('output_format', 'zip', ['zip', 'tgz', 'tar'], 'What format to use for --output_file.') flags.DEFINE_enum( 'output_type', 'plain', ['plain', 'full'], 'What kind of output to make.' ' plain=just the source,' ' full=turn on all the optional parts (useful for testing the generator).') flags.DEFINE_string( 'templates', None, 'The name of the template suite (w.r.t. language and variant)') flags.DEFINE_bool('version_package', False, 'Put API version in package paths') flags.DECLARE_key_flag('discovery') flags.DECLARE_key_flag('include_timestamp') flags.DECLARE_key_flag('language') flags.DECLARE_key_flag('language_variant') flags.DECLARE_key_flag('output_dir') flags.DECLARE_key_flag('output_file') flags.DECLARE_key_flag('output_format') flags.DECLARE_key_flag('output_type') flags.DECLARE_key_flag('templates') flags.DECLARE_key_flag('version_package') def main(unused_argv): if not FLAGS.discovery: raise app.UsageError('You must specify --discovery') if not (FLAGS.output_dir or FLAGS.output_file):
'An output file path to contain the archive for the generated library.' ' The contents of the file are determined by the output_format parameter') flags.DEFINE_enum('output_format', 'zip', ['zip', 'tgz', 'tar', 'txt'], 'What format to use for --output_file.') flags.DEFINE_enum( 'output_type', 'plain', ['plain', 'full'], 'What kind of output to make.' ' plain=just the source,' ' full=turn on all the optional parts (useful for testing the generator).') flags.DEFINE_string( 'package_path', None, 'Use an alternate path for the generated code. This must be a file path' ' using "/" as a separator, not "."') flags.DEFINE_bool('version_package', False, 'Put API version in package paths') flags.DEFINE_bool('verbose', False, 'Enable verbose logging') flags.DECLARE_key_flag('api_name') flags.DECLARE_key_flag('api_version') flags.DECLARE_key_flag('include_timestamp') flags.DECLARE_key_flag('input') flags.DECLARE_key_flag('language') flags.DECLARE_key_flag('language_variant') flags.DECLARE_key_flag('monolithic_source_name') flags.DECLARE_key_flag('output_dir') flags.DECLARE_key_flag('output_file') flags.DECLARE_key_flag('output_format') flags.DECLARE_key_flag('output_type') flags.DECLARE_key_flag('package_path') flags.DECLARE_key_flag('version_package') def main(unused_argv):
def DeclareKeyFlags(): """Declares a few key flags.""" for flag_name in DECLARED_KEY_FLAGS: flags.DECLARE_key_flag(flag_name)
#!/usr/bin/env python """Adopts all flags from libfoo and one flag from libbar.""" import gflags from gflags.examples import libbar # pylint: disable=unused-import from gflags.examples import libfoo gflags.DEFINE_integer('num_iterations', 0, 'Number of iterations.') # Declare that all flags that are key for libfoo are # key for this module too. gflags.ADOPT_module_key_flags(libfoo) # Declare that the flag --bar_gfs_path (defined in libbar) is key # for this module. gflags.DECLARE_key_flag('bar_gfs_path')
'language_variant', 'default', 'which variant of "language" to generate for. E.g. "stable" vs. "head".') flags.DEFINE_string( 'output_dir', None, 'A path to a directory where the generated files will be created.') flags.DEFINE_string( 'output_file', None, 'An output file path to contain the archive for the generated library.' ' The contents of the file are determined by the output_format parameter') flags.DEFINE_enum( 'output_type', 'plain', ['plain', 'full'], 'What kind of output to make.' ' plain=just the source,' ' full=turn on all the optional parts (useful for testing the generator).') flags.DEFINE_bool('version_package', False, 'Put API version in package paths') flags.DECLARE_key_flag('api_name') flags.DECLARE_key_flag('api_version') flags.DECLARE_key_flag('discovery_server') flags.DECLARE_key_flag('discovery_version') flags.DECLARE_key_flag('include_timestamp') flags.DECLARE_key_flag('input') flags.DECLARE_key_flag('language') flags.DECLARE_key_flag('language_variant') flags.DECLARE_key_flag('output_dir') flags.DECLARE_key_flag('output_file') flags.DECLARE_key_flag('output_type') flags.DECLARE_key_flag('version_package') def main(unused_argv): if not (FLAGS.api_name or FLAGS.input):