Getopt...::Args(3pm)

πŸ“¦
version 0.26 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Getopt::Complete::Args β€” a whole little set of option/value pairs, bestie πŸ’…


πŸ¦‹ VERSION πŸ¦‹

This doc is describing Getopt::Complete::Args version 0.26, periodt.


✨ SYNOPSIS ✨

okay so real talk: this thing is used internally by Getopt::Complete when it compiles. Like, it's the backstage crew, not the main character. πŸŽ€

But if you wanna hand-build your own implementation and use the objects directly, it could look exactly like this:

# process @ARGV...

my $args = Getopt::Complete::Args->new(
   options => [                            # or pass a Getopt::Complete::Options directly
       'myfiles=s@' => 'f',
       'name'       => 'u',
       'age=n'      => undef,
       'fast!'      => undef,
       'color'      => ['red','blue','yellow'],
   ]
   argv => \@ARGV
);

$args->options->handle_shell_completion;   # support 'complete -F _getopt_complete myprogram'

if (my @e = $args->errors) {
   for my $e (@e) {
       warn $e;
   }
   exit 1;
}

# on to normal running of the program...

for my $name ($args->option_names) {
   my $spec = $args->option_spec($name);
   my $value = $args->value($name);
   print "option $name has specification $spec and value $value\n";
}

like, slay. that's the whole vibe. 🫢


🌸 DESCRIPTION 🌸

An object of this class is literally a set of option/value pairs πŸ‘‘ β€” and it's built from a Getopt::Complete::Options object plus a list of command-line arguments (@ARGV).

Not me telling you that this is the class of the $Getopt::Complete::ARGS object, and the $ARGS alias that gets created at compile time 🫣 It's also the source of the %ARGS hash that gets injected into both of those namespaces at compile time. iconic behavior tbh.


πŸŽ€ METHODS πŸŽ€

argv

Returns the list of original command-line arguments. the receipts, basically πŸ’…

options

Returns the Getopt::Complete::Options object that was used to parse the command-line.

value($option_name)

Returns the value for a given option name, after parsing. yes queen, post-parse.

bare_args

Returns the bare arguments. it's the same as ->value('<>') πŸ“

parent_sub_commands

When you're using a tree of sub-commands, this gives you the list of sub-commands that were selected, in order, to get to this point. 🌈 The options and option/value pairs apply to just this particular sub-command.

It's the same as ->value('>').

⚠️ bestie this is distinct from ->sub_commands(), which returns the list of next possible choices when drilling down. don't mix them up, i'm begging 😭

option_spec($name)

Returns the GetOptions specification for the parameter in question.

completion_handler($name)

Returns the arrayref or code ref that handles resolving valid completions. she does the thinking for you πŸ’­

sub_commands

The list of sub-commands which are options at this level of a command tree. 🌳

This is distinct from sub_command_path, which is the sub-commands that were chosen to get to this level in the tree. two different things, both slaying πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

  • Getopt::Complete
  • Getopt::Complete::Options
  • Getopt::Complete::Compgen

go read those too, iykyk πŸ’œ


Copyright 2010 Scott Smith and Washington University School of Medicine


πŸ‘‘ AUTHORS πŸ‘‘

Scott Smith (sakoht at cpan .org)


🌈 LICENSE 🌈

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


and that's the whole page, bestie!! πŸŽ€βœ¨ this was Getopt...::Args(3pm) from the User Contributed Perl Documentation, perl v5.36.0, dated 2022-10-13. mwah, go forth and parse πŸ’…πŸ’–

πŸ“¦ where this page comes from