From c316d8b5291115ba36996e884f683c2820f59b6f Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 10 May 2019 13:53:02 +0300 Subject: [PATCH] Reduce some code duplication in CLI arguments --- kitti2bag/__init__.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/kitti2bag/__init__.py b/kitti2bag/__init__.py index b74ab79..20e9261 100755 --- a/kitti2bag/__init__.py +++ b/kitti2bag/__init__.py @@ -231,27 +231,33 @@ def save_gps_vel_data(bag, kitti, gps_frame_id, topic): @click.group() +@click.help_option('-h', '--help') def cli(): """Convert KITTI dataset to ROS bag file the easy way!""" pass +def common_options(f): + f = click.option("-i", "--input-dir", required=False, default='.', show_default=True, + type=click.Path(exists=True, dir_okay=True, file_okay=False), + help="base directory of the dataset")(f) + f = click.option("-o", "--output-dir", required=False, default='.', show_default=True, + type=click.Path(exists=True, dir_okay=True, file_okay=False), + help="output directory for the created bag file")(f) + f = click.option("--compression", required=False, + type=click.Choice(compression_choices), + default=rosbag.Compression.NONE, show_default=True, + help="which compression to use for the created bag")(f) + f = click.help_option('-h', '--help')(f) + return f + + @cli.command('raw') @click.option("-t", "--date", required=True, metavar='DATE', help="date of the raw dataset (i.e. 2011_09_26)") @click.option("-r", "--drive", required=True, type=int, help="drive number of the raw dataset (i.e. 1)") -@click.option("-i", "--input-dir", required=False, default='.', show_default=True, - type=click.Path(exists=True, dir_okay=True, file_okay=False), - help="base directory of the dataset") -@click.option("-o", "--output-dir", required=False, default='.', show_default=True, - type=click.Path(exists=True, dir_okay=True, file_okay=False), - help="output directory for the created bag file") -@click.option("--compression", required=False, - type=click.Choice(compression_choices), - default=rosbag.Compression.NONE, show_default=True, - help="which compression to use for the created bag") -@click.help_option('-h', '--help') +@common_options def convert_raw(date, drive, input_dir='.', output_dir='.', compression=rosbag.Compression.NONE): """Convert a raw synced+rectified KITTI dataset to a bag""" drive = str(drive).zfill(4) @@ -293,17 +299,7 @@ def convert_raw(date, drive, input_dir='.', output_dir='.', compression=rosbag.C help="sequence number") @click.option("-c", "--color", type=click.Choice(['gray', 'color', 'all']), required=True, help="which camera images to include in the bag") -@click.option("-i", "--input-dir", required=False, default='.', show_default=True, - type=click.Path(exists=True, dir_okay=True, file_okay=False), - help="base directory of the dataset") -@click.option("-o", "--output-dir", required=False, default='.', show_default=True, - type=click.Path(exists=True, dir_okay=True, file_okay=False), - help="output directory for the created bag file") -@click.option("--compression", required=False, - type=click.Choice(compression_choices), - default=rosbag.Compression.NONE, show_default=True, - help="which compression to use for the created bag") -@click.help_option('-h', '--help') +@common_options def convert_odom(sequence, color, input_dir='.', output_dir='.', compression=rosbag.Compression.NONE): """Convert an odometry KITTI dataset to a bag""" sequence_str = str(sequence).zfill(2)