@@ -486,11 +486,12 @@ def get_all_options(
486486 drop_default = False ,
487487 add_extra_args_fn : Optional [Callable [[_BeamArgumentParser ], None ]] = None ,
488488 retain_unknown_options = False ,
489- display_warnings = False ) -> Dict [str , Any ]:
489+ display_warnings = False ,
490+ current_only = False ,
491+ ) -> Dict [str , Any ]:
490492 """Returns a dictionary of all defined arguments.
491493
492- Returns a dictionary of all defined arguments (arguments that are defined in
493- any subclass of PipelineOptions) into a dictionary.
494+ Returns a dictionary of all defined arguments into a dictionary.
494495
495496 Args:
496497 drop_default: If set to true, options that are equal to their default
@@ -500,6 +501,9 @@ def get_all_options(
500501 retain_unknown_options: If set to true, options not recognized by any
501502 known pipeline options class will still be included in the result. If
502503 set to false, they will be discarded.
504+ current_only: If set to true, only returns options defined in this class.
505+ Otherwise, arguments that are defined in any subclass of PipelineOptions
506+ are returned (default).
503507
504508 Returns:
505509 Dictionary of all args and values.
@@ -510,8 +514,11 @@ def get_all_options(
510514 # instance of each subclass to avoid conflicts.
511515 subset = {}
512516 parser = _BeamArgumentParser (allow_abbrev = False )
513- for cls in PipelineOptions .__subclasses__ ():
514- subset .setdefault (str (cls ), cls )
517+ if current_only :
518+ subset .setdefault (str (type (self )), type (self ))
519+ else :
520+ for cls in PipelineOptions .__subclasses__ ():
521+ subset .setdefault (str (cls ), cls )
515522 for cls in subset .values ():
516523 cls ._add_argparse_args (parser ) # pylint: disable=protected-access
517524 if add_extra_args_fn :
@@ -562,7 +569,7 @@ def add_new_arg(arg, **kwargs):
562569 continue
563570 parsed_args , _ = parser .parse_known_args (self ._flags )
564571 else :
565- if unknown_args :
572+ if unknown_args and not current_only :
566573 _LOGGER .warning ("Discarding unparseable args: %s" , unknown_args )
567574 parsed_args = known_args
568575 result = vars (parsed_args )
@@ -580,7 +587,7 @@ def add_new_arg(arg, **kwargs):
580587 if overrides :
581588 if retain_unknown_options :
582589 result .update (overrides )
583- else :
590+ elif not current_only :
584591 _LOGGER .warning ("Discarding invalid overrides: %s" , overrides )
585592
586593 return result
0 commit comments