Skip to content

Commit

Permalink
Reduce some code duplication in CLI arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed May 10, 2019
1 parent 7d053bb commit 5ae7fa5
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions kitti2bag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,34 @@ 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(function):
@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')
def tmp(*args, **kwargs):
function(*args, **kwargs)
return tmp

@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)
Expand Down Expand Up @@ -293,17 +300,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)
Expand Down

0 comments on commit 5ae7fa5

Please sign in to comment.