Code Duplication    Length = 31-31 lines in 2 locations

hansel/cli/cli.py 2 locations

@@ 153-183 (lines=31) @@
150
@click.argument('crumb1', type=CrumbPath(), callback=check_not_none)
151
@click.argument('crumb2', type=CrumbPath(), callback=check_not_none)
152
@click.option('-o', '--on', type=str, multiple=True,
153
              help='Argument name to check for intersection. You can use this '
154
                   'argument more than once.')
155
@click.option('-b', '--base', type=click.Choice(['1', '2']), default='0',
156
              help='1 or 2, to indicate `crumb1` or `crumb2` as a base crumb2 '
157
                   'to print the results')
158
def diff(crumb1, crumb2, on, base):
159
    """Return the difference crumb1 - crumb2 on a given argument.
160
161
    Will not print full paths, but only values for the crumb arguments in `on`.
162
    Unless you specify the crumb you want to use as a base with the `base`
163
    argument.
164
165
    Examples: \n
166
    crumb diff --on "sid" "/data/hansel/cobre/{sid}/{session}/{img}" "/data/hansel/cobre2/{sid}/{img}"\n
167
    """
168
    from .. import difference
169
170
    values = difference(crumb1, crumb2, on=on)
171
    if base == '0':
172
        _print_values_map_as_csv(values)
173
    else:
174
        if base == '1':
175
            base_crumb = crumb1
176
        else:
177
            base_crumb = crumb2
178
179
        echo_list(base_crumb.build_paths(values))
180
@@ 120-150 (lines=31) @@
117
@click.argument('crumb1', type=CrumbPath(), callback=check_not_none)
118
@click.argument('crumb2', type=CrumbPath(), callback=check_not_none)
119
@click.option('-o', '--on', type=str, multiple=True,
120
              help='Argument name to check for intersection. You can use this '
121
                   'argument more than once.')
122
@click.option('-b', '--base', type=click.Choice(['1', '2']), default='0',
123
              help='1 or 2, to indicate `crumb1` or `crumb2` as a base crumb2 '
124
                   'to print the results')
125
def intersect(crumb1, crumb2, on, base):
126
    """Return the intersection between crumb1 and crumb2 on a given argument.
127
128
    Will not print full paths, but only values for the crumb arguments in `on`.
129
    Unless you specify the crumb you want to use as a base with the `base`
130
    argument.
131
132
    Examples: \n
133
    crumb intersect --on "sid" "/data/hansel/cobre/{sid}/{session}/{img}" "/data/hansel/cobre2/{sid}/{img}"\n
134
    """
135
    from .. import intersection
136
137
    values = intersection(crumb1, crumb2, on=on)
138
    if base == '0':
139
        _print_values_map_as_csv(values)
140
    else:
141
        if base == '1':
142
            base_crumb = crumb1
143
        else:
144
            base_crumb = crumb2
145
146
        echo_list(base_crumb.build_paths(values))
147
148
149
@cli.command(context_settings=CONTEXT_SETTINGS)
150
@click.argument('crumb1', type=CrumbPath(), callback=check_not_none)
151
@click.argument('crumb2', type=CrumbPath(), callback=check_not_none)
152
@click.option('-o', '--on', type=str, multiple=True,
153
              help='Argument name to check for intersection. You can use this '