Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to set up custom argument parsers #2279

Closed
zoffixznet opened this issue Sep 15, 2018 · 9 comments
Closed

Make it easier to set up custom argument parsers #2279

zoffixznet opened this issue Sep 15, 2018 · 9 comments
Labels
RFC Request For Comments

Comments

@zoffixznet
Copy link
Contributor

zoffixznet commented Sep 15, 2018

Based off http://colabti.org/irclogger/irclogger_log/perl6?date=2018-09-15#l316

13:30 | leont | Sure, but given that there isn't any non-internal way to do this,
      I would still like it to keep working.
-- | -- | --
13:30 | leont | Now working around it with a multi, but it's a bit unfortunate.
13:30 | Zoffix | leont: "do this" is do what?
13:30 | leont | Install a different argument parser
13:31 | Zoffix | leont: and basically replace the MAIN_HELPER with a new sub?
13:32 | leont | Yeah. I'm not even the first to do that.

I'm imagining a module that sets something in %*SUB-MAIN-OPTS (e.g. assigns a custom Callable to some key) affect how the arguments are parsed. I'm hoping that's possible to do in a way that the use of that module would just be able to use GetOpt::Whatever and not have to modify SUB-MAIN-OPTS themselves.

@zoffixznet zoffixznet added the RFC Request For Comments label Sep 15, 2018
@Leont
Copy link
Contributor

Leont commented Sep 18, 2018

I'm imagining a module that sets something in %*SUB-MAIN-OPTS (e.g. assigns a custom Callable to some key) affect how the arguments are parsed.

That sounds sensible enough. Something that takes a Sub (and the options?) and returns a Capture

@Leont
Copy link
Contributor

Leont commented Sep 18, 2018

Is it possible to create a contextual variable in an outer scope though?

@zoffixznet
Copy link
Contributor Author

a contextual variable

No idea what that is. Do you mean dynamic? One way would be to stick it into PROCESS::

$ perl6 -e 'sub foo { PROCESS::<$MEOWS> = 42 }; foo; say $*MEOWS'
42

@Leont
Copy link
Contributor

Leont commented Sep 18, 2018

Yeah I meant dynamic. I'm not sure that solution really is better than our current, at least MAIN_HELPER is scoped!

@zoffixznet
Copy link
Contributor Author

zoffixznet commented Sep 18, 2018

Does that even matter? Isn't there only one MAIN (even if it's a bunch of multies) that would get processed? And %*SUB-MAIN-OPTS is the official hash with MAIN handling options.

In fact, it was global briefly before, but was removed so that we don't pay for its initialization when the user isn't gonna use it.

@zoffixznet
Copy link
Contributor Author

Also, we could have something similar to how you can do use Foo:from<Perl5> without having to explicitly use Inline::Perl5, so that the user would specify which processor they want by declaring the %*SUB-MAIN-OPTS. Something like

    my %*SUB-MAIN-OPTS = :processor<Awesome>;

And that would automatically load GetOpt::Awesome module and use its callable from its predefined method or something (sort-of how we handle custom exeption handlers with Exceptions::BlahBlah and setting env var to BlahBlah string)

@Leont
Copy link
Contributor

Leont commented Oct 2, 2018

To be honest, the old (pre 2018.06) MAIN_HELPER still looks like the best interface I've seen so far.

@zoffixznet
Copy link
Contributor Author

zoffixznet commented Oct 11, 2018

@Leont would you be able to take new MAIN helpers out for a spin and see if they resolve this ticket?

@Leont
Copy link
Contributor

Leont commented Oct 12, 2018

Yeah it looks sensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

2 participants