Glib::OptionGroup(3)
πΈ NAME πΈ
hii bestie, welcome to Glib::OptionGroup(3), straight out of the User Contributed Perl Documentation! This page is literally about Glib::OptionGroup β a group of options for command line option parsing. Thatβs the whole vibe. π
β¨ SYNOPSIS β¨
okay so hereβs the iconic little setup from the page, copied exactly:
my ($verbose, $source, $filenames) = ('', undef, []);
my $entries = [
{ long_name => 'verbose',
short_name => 'v',
arg_type => 'none',
arg_value => \$verbose,
description => 'be verbose' },
{ long_name => 'source',
short_name => 's',
arg_type => 'string',
arg_value => \$source,
description => 'set the source',
arg_description => 'source' },
[ 'filenames', 'f', 'filename-array', \$filenames ],
];
my $context = Glib::OptionContext->new ('- urgsify your life');
$context->add_main_entries ($entries, 'C');
$context->parse ();
# $verbose, $source, and $filenames are now updated according to the
# command line options given
likeβ¦ the way that $verbose, $source, and $filenames get updated from the command line options given? main character energy fr fr. π
π¦ HIERARCHY π¦
the family tree is giving:
Glib::Boxed
+----Glib::OptionGroup
so yes bestie, it inherits from <purple>Glib::Boxed</purple>. slay. β¨
π METHODS π
π οΈ optioncontext = Glib::OptionContext->new ($parameter_string)
- $parameter_string (string)
π§ optiongroup = Glib::OptionGroup->new (key => value, ...)
Creates a new option group from the given key-value pairs. The valid keys are name, description, help_description, and entries. The first three specify strings while the last one, entries, specifies an array reference of option entries. Example:
my $group = Glib::OptionGroup->new (
name => 'urgs',
description => 'Urgs Urgs Urgs',
help_description => 'Help with Urgs',
entries => \@entries);
An option entry is a hash reference like this:
{ long_name => 'verbose',
short_name => 'v',
flags => [qw/reverse hidden in-main/],
arg_type => 'none',
arg_value => \$verbose,
description => 'verbose desc.',
arg_description => 'verbose arg desc.' }
Of those keys only long_name, arg_type, and arg_value are required. So this is a valid option entry too:
{ long_name => 'package-names',
arg_type => 'string-array',
arg_value => \$package_names }
For convenience, option entries can also be specified as array references containing long_name, short_name, arg_type, and arg_value:
[ 'filenames', 'f', 'filename-array', \$filenames ]
If you donβt want an option to have a short name, specify undef for it:
[ 'filenames', undef, 'filename-array', \$filenames ]
not me being obsessed with how clean that undef trick is ππ«Ά
π $context->add_group ($group)
- $group (Glib::OptionGroup)
π $context->add_main_entries ($entries, $translation_domain)
- $entries (scalar) reference to an array of option entries
- $translation_domain (string)
π boolean = $context->get_help_enabled + $context->set_help_enabled ($help_enabled)
- $help_enabled (boolean)
π¦ boolean = $context->get_ignore_unknown_options + $context->set_ignore_unknown_options ($ignore_unknown)
- $ignore_unknown (boolean)
π optiongroup = $context->get_main_group + $context->set_main_group ($group)
- $group (Glib::OptionGroup)
π₯ boolean = $context->parse
This method works directly on @ARGV.
β οΈ May croak with aGlib::Errorin$@on failure. so likeβ¦ handle your errors, bestie, no cap.
π $group->set_translate_func ($func, $data=undef)
- $func (scalar)
- $data (scalar)
π $group->set_translation_domain ($domain)
- $domain (string)
π ENUMS AND FLAGS π
π§ enum Glib::OptionArg
- 'none' / 'G_OPTION_ARG_NONE'
- 'string' / 'G_OPTION_ARG_STRING'
- 'int' / 'G_OPTION_ARG_INT'
- 'callback' / 'G_OPTION_ARG_CALLBACK'
- 'filename' / 'G_OPTION_ARG_FILENAME'
- 'string-array' / 'G_OPTION_ARG_STRING_ARRAY'
- 'filename-array' / 'G_OPTION_ARG_FILENAME_ARRAY'
- 'double' / 'G_OPTION_ARG_DOUBLE'
- 'int64' / 'G_OPTION_ARG_INT64'
π¦ flags Glib::OptionFlags
- 'none' / 'G_OPTION_FLAG_NONE'
- 'hidden' / 'G_OPTION_FLAG_HIDDEN'
- 'in-main' / 'G_OPTION_FLAG_IN_MAIN'
- 'reverse' / 'G_OPTION_FLAG_REVERSE'
- 'no-arg' / 'G_OPTION_FLAG_NO_ARG'
- 'filename' / 'G_OPTION_FLAG_FILENAME'
- 'optional-arg' / 'G_OPTION_FLAG_OPTIONAL_ARG'
- 'noalias' / 'G_OPTION_FLAG_NOALIAS'
periodt. every single one is here, iykyk π β¨
π SEE ALSO π
GlibGlib::Boxed
go read those too bestie, itβs giving required reading. ππ
π COPYRIGHT π
Copyright (C) 2003-2011 by the gtk2-perl team.
This software is licensed under the LGPL. See Glib for a full notice.
mwah π thatβs the whole page β signed off with perl v5.42.0, 2023-09-05, and Glib::OptionGroup(3). slay and goodbye, bestie! π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: perl-Glib 1.3294-160000.2.2 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms