clk-project / clk

A very opinionated framework to ease the creation of command line interfaces
https://clk-project.org/
MIT License
22 stars 6 forks source link

`flow_option` over options with `multiple=True` breaks when multiple options are passed #22

Closed neomatamune closed 1 year ago

neomatamune commented 1 year ago

Using this small example you can reproduce the issue:

from clk.decorators import command, option

@command()
@option("-o", "--option", "o", multiple=True)
def working_cmd(o):
    """Calling this command with -o A -o B does not break"""
    print(o)
from clk.decorators import flow_command
from clk.overloads import get_command

work = get_command("working-cmd")

@flow_command()
@work.flow_option("o")
def flow_bug(**options):
    """Calling this command with -o A -o B breaks"""

Calling working-cmd -o A -o B will work, while calling flow-bug -o A -o B will break

The issue seems to come from either clk.flow.get_flow_wrapper where the function clk.lib.flat_map is called with a generator of tuples as a parameter, or directly in the clk.lib.flat_map function that does not check if it content are lists.

A simple correction would be to replace the line elem = list(elem) by elem = list(map(list, elem)) but it could have effect elsewhere in the code base so I only put it as a proposition here.

Konubinix commented 1 year ago

Thank you for this issue. It is very appreciated. Can you provide a pull request with the correction?

Konubinix commented 1 year ago

See #23