This is what I came up with to replicate the desired behavior.
In this use case, the user has already downloaded a file with some number of unsigned messages (n_messages). The user then signs the messages via a separate process. And, then uploads the signed messages along with a file that contains the unsigned messages using the @click.command signed.
Here is the @click.command:
@main.command()
@ click.argument('file', type=click.File('r'), required=True)
@click.option('-sig', 'signatures', type=click.File('r'), multiple=True, required=True, cls=VerifySigNumbers)
def signed(*args, **kwargs):
create_signed_tx(*args, **kwargs)
Here is the custom class:
class VerifySigNumbers(click.Option):
def __init__(self, *args, **kwargs):
super(VerifySigNumbers, self).__init__(*args, **kwargs)
def handle_parse_result(self, ctx, opts, args):
pig_file = opts.get('file')
data = read_pig_file(file)
n_messages = data.get('n_messages')
signatures = opts.get('signatures')
n_sigs = 0 if signatures is None else len(signatures)
if n_sigs != n_messages:
raise click.UsageError(
f'{pig_file} requires {n_tx_inputs} signatures, {n_sigs} provided', ctx)
return super(VerifySigNumbers, self).handle_parse_result(ctx, opts, args)
I would like the users to be prompt for the unsigned messages, but unsure how to implement it. Additionally, I ran into an issue uploading files via a prompt.