nysus has asked for the wisdom of the Perl Monks concerning the following question:

If I use the --help switch for a command I wrote using MooseX::App::Cmd::Command, which relies on MooseX::Getopt, the order of the switches is random. For example:

~/workshop/dist_zilla: dz create_commands -h dz create_commands [-?cdhs] [long options...] creates commands for a dzil profile minted with "cli" -h -? --usage --help Prints this usage information. -d STR --dir STR directory where distribution is located -c STR --cmd STR name of the command to create -s STR... --subcmd STR... name of a subcommand to create ~/workshop/dist_zilla: dz create_commands -h dz create_commands [-?cdhs] [long options...] creates commands for a dzil profile minted with "cli" -d STR --dir STR directory where distribution is located -c STR --cmd STR name of the command to create -s STR... --subcmd STR... name of a subcommand to create -h -? --usage --help Prints this usage information.

Kind of annoying. I'd like them to be output alphabetically. I did not see an option for this, though.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Is there a way to order --help argument list output by getopt?
by nysus (Parson) on Feb 03, 2018 at 23:07 UTC

    I'm just noticing that the sort order of my arguments is the same order as they were defined, it's just the help switch that is getting mixed in with them that appears in random order.

    I also just found the MooseX::Getopt::Usage module. Neat, but doesn't seem to have a way to fix this issue.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      I've never used this module, but ...

      > the help switch that is getting mixed in with them that appears in random order.

      Your examples show -h not at a random position but either on the first or last position, this seems sensible for a generated switch.

      What happens if you include -h in your fixed list?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

        The -h also sometimes appears mixed with the other options:

        creates commands for a dzil profile minted with "cli" -d STR --dir STR directory where distribution is located -c STR --cmd STR command name -h -? --usage --help Prints this usage information. -s STR... --subcmd STR... subcommands to create

        If I switch one of the options to -h as well, I get this:

        creates commands for a dzil profile minted with "cli" -h STR --dir STR directory where distribution is located -c STR --cmd STR command name -h -? --usage --help Prints this usage information. -s STR... --subcmd STR... subcommands to create

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks