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

RFC: Allow subcommands in MAIN #688

Closed
wants to merge 2 commits into from
Closed

RFC: Allow subcommands in MAIN #688

wants to merge 2 commits into from

Conversation

Juerd
Copy link
Contributor

@Juerd Juerd commented Jan 22, 2016

The combination of these two patches will allow subcommands like in "git" or "apt".

Note that f8227bb deliberately goes against spec (S06), which says:

As usual, switches are assumed to be first, and everything after the first non-switch, or any switches after a --, are treated as positionals or go into the slurpy array (even if they look like switches)

S06 is demonstrably wrong in that this would be the usual thing, since all these standard tools apparently take switches after positionals:

1;0 juerd@cxie:~$ wc $(ls $(which perl6 -a) -1) --chars
26876 /home/juerd/.rakudobrew/bin/perl6

Requiring switches at the beginning is common with BSD-style command line parsing, but that style doesn't have --long-names or --, both of which are already supported by Perl 6.

This patch set has not yet been thoroughly tested. Please discuss and test :-)

Perl6 was GNU-like in that it has '--double-dashes' and that it stops
interpreting named parameters when it encounters '--', but unlike GNU-like
parsing, it also stopped interpreting named parameters when encountering any
positional argument.

This patch makes it a bit more GNU-like by allowing named arguments after
a positional, to prepare for allowing subcommands.
Assuming that positional literal strings at the beginning of a signature
are subcommands, they go before any named arguments.
@Juerd
Copy link
Contributor Author

Juerd commented Jan 22, 2016

Demonstration:

1;0 juerd@cxie:~$ cat gitlike.pl 
multi sub MAIN ("add", *@pathspec, Bool :v($verbose), Bool :n($dry-run), Bool :i($interactive)) { die 1 }
multi sub MAIN ("commit", *@file, Bool :$e, Bool :$dry-run, Str :$author) { die 2 }
multi sub MAIN ("diff", Str $path1, Str $path2, Bool :$no-index) { die 3 }

1;0 juerd@cxie:~$ perl6 gitlike.pl 
Usage:
  gitlike.pl add [-v] [-n] [-i] [<pathspec> ...] 
  gitlike.pl commit [-e] [--dry-run] [--author=<Str>] [<file> ...] 
  gitlike.pl diff [--no-index] <path1> <path2> 
1;2 juerd@cxie:~$ perl6 gitlike.pl add
1
  in sub MAIN at gitlike.pl line 1
  in block <unit> at gitlike.pl line 3

1;1 juerd@cxie:~$ perl6 gitlike.pl diff foo bar
3
  in sub MAIN at gitlike.pl line 3
  in block <unit> at gitlike.pl line 3

@vendethiel
Copy link
Contributor

Yes yes yes! That's a very good idea 👍 .

@lizmat
Copy link
Contributor

lizmat commented Jan 22, 2016

I'm afraid merging this will have to wait until we have a decision on how to technically handle versioning

@Juerd
Copy link
Contributor Author

Juerd commented Jan 22, 2016

I understand that merging might have to wait on that decision. In the meantime, it remains important that we discuss whether we WANT to merge it, since it would require a spec change.

@b2gills
Copy link
Contributor

b2gills commented Jan 22, 2016

As far as I can tell the only person who has been against this sort of change at all is Tim Toady.
(+1 from me)

@MadcapJake
Copy link
Contributor

Can this be considered for inclusion in 2016.03 under v6.d.a?

@jnthn
Copy link
Member

jnthn commented Feb 22, 2016

TimToady would need to rule on the language design issue. I suspect it
breaks back-compat, so would need to go in the 6.d setting.

On Mon, Feb 22, 2016 at 6:22 PM, Jake Russo notifications@github.com
wrote:

Can this be considered for inclusion in 2016.03 under v6.d.a?


Reply to this email directly or view it on GitHub
#688 (comment).

@AlexDaniel
Copy link
Contributor

It may be a bit too late but: YES!!

@niner
Copy link
Collaborator

niner commented Feb 23, 2016

What if there should be a distinction between global and subcommand specific options as in:
zypper -v search --match-exact Mesa

@LLFourn
Copy link
Contributor

LLFourn commented Feb 23, 2016

👍 Would be cool if we could also

sub MAIN($ where 'foo'|'bar', :$baz) { ... } # PS why can't we just write sub MAIN('foo'|'bar',...)
Usage:
  gitlike.pl [ foo | bar ] [-baz]

@niner I cannot think of a way to describe main options and subcommand options with signatures

@LLFourn
Copy link
Contributor

LLFourn commented Feb 23, 2016

Idea: what about for global switches we introspect the dispatcher's signature:

# to use nine's example
proto MAIN(:$v #={verbose output},|) { $*VERBOSE = True if $v; {*} }
multi MAIN("search",Bool :$match-exact,Str $target) { ... }

Then the help could look like:

Options: 
  -v     verbose output
Usage:
  zypper [OPTIONS] search <target> [--match-exact]

What I'm suggesting is all cosmetic so I think @niner's concern above can be addressed after this is merged.

@Juerd
Copy link
Contributor Author

Juerd commented Dec 13, 2016

Can someone explain what the next steps are in the process of reaching a decision?

@zoffixznet
Copy link
Contributor

Can someone explain what the next steps are in the process of reaching a decision?

Does this PR break any of the current tests?

If yes,

Write your proposal into https://github.com/perl6/specs/blob/master/v6d.pod , listing yourself as stakeholder. The change will be considered for inclusion in the next language release. Note that that won't happen in a near future (I saw dates named anywhere for summer 2017 to Diwalli 2017, which is sometime in October).

If no tests break,

Then hunt down TimToady and ask him to make a decision on whether this language design change is OK. If he agrees, fix merge conflicts, and ping one of the people who can merge to merge.

Hope that helps.

@AlexDaniel AlexDaniel added the severe A problem that is encountered frequently, or a problem that needs attention for other reasons label Jun 25, 2018
@Juerd
Copy link
Contributor Author

Juerd commented May 14, 2019

Basically fixed in af14584 and 0d1be77 as discussed in #2246.

@Juerd Juerd closed this May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts severe A problem that is encountered frequently, or a problem that needs attention for other reasons
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet