2828from absl import app
2929from absl import flags
3030from absl import logging
31- from absl .flags import argparse_flags
3231
32+ import simple_parsing
3333import tensorflow_datasets .public_api as tfds
3434
3535# Import commands
@@ -46,7 +46,7 @@ def _parse_flags(argv: List[str]) -> argparse.Namespace:
4646 """Command lines flag parsing."""
4747 argv = flag_utils .normalize_flags (argv ) # See b/174043007 for context.
4848
49- parser = argparse_flags .ArgumentParser (
49+ parser = simple_parsing .ArgumentParser (
5050 description = 'Tensorflow Datasets CLI tool' ,
5151 allow_abbrev = False ,
5252 )
@@ -67,7 +67,22 @@ def _parse_flags(argv: List[str]) -> argparse.Namespace:
6767 new .register_subparser (subparser )
6868 convert_format .register_subparser (subparser )
6969 croissant .register_subparser (subparser )
70- return parser .parse_args (argv [1 :])
70+
71+ namespace , remaining_argv = parser .parse_known_args (argv [1 :])
72+
73+ # Manually parse absl flags from the remaining arguments.
74+ try :
75+ # FLAGS requires the program name as the first argument.
76+ positionals = FLAGS (argv [:1 ] + remaining_argv )
77+ except flags .Error as e :
78+ parser .error (str (e ))
79+
80+ # There should be no positional arguments left, as they should have been
81+ # handled by the sub-commands.
82+ if len (positionals ) > 1 :
83+ parser .error (f"unrecognized arguments: { ' ' .join (positionals [1 :])} " )
84+
85+ return namespace
7186
7287
7388def main (args : argparse .Namespace ) -> None :
0 commit comments