1Glib::OptionGroup(3) User Contributed Perl Documentation Glib::OptionGroup(3)
2
3
4
6 Glib::OptionGroup - group of options for command line option parsing
7
9 my ($verbose, $source, $filenames) = ('', undef, []);
10
11 my $entries = [
12 { long_name => 'verbose',
13 short_name => 'v',
14 arg_type => 'none',
15 arg_value => \$verbose,
16 description => 'be verbose' },
17
18 { long_name => 'source',
19 short_name => 's',
20 arg_type => 'string',
21 arg_value => \$source,
22 description => 'set the source',
23 arg_description => 'source' },
24
25 [ 'filenames', 'f', 'filename-array', \$filenames ],
26 ];
27
28 my $context = Glib::OptionContext->new ('- urgsify your life');
29 $context->add_main_entries ($entries, 'C');
30 $context->parse ();
31
32 # $verbose, $source, and $filenames are now updated according to the
33 # command line options given
34
36 Glib::Boxed
37 +----Glib::OptionGroup
38
40 optioncontext = Glib::OptionContext->new ($parameter_string)
41 • $parameter_string (string)
42
43 optiongroup = Glib::OptionGroup->new (key => value, ...)
44 Creates a new option group from the given key-value pairs. The valid
45 keys are name, description, help_description, and entries. The first
46 three specify strings while the last one, entries, specifies an array
47 reference of option entries. Example:
48
49 my $group = Glib::OptionGroup->new (
50 name => 'urgs',
51 description => 'Urgs Urgs Urgs',
52 help_description => 'Help with Urgs',
53 entries => \@entries);
54
55 An option entry is a hash reference like this:
56
57 { long_name => 'verbose',
58 short_name => 'v',
59 flags => [qw/reverse hidden in-main/],
60 arg_type => 'none',
61 arg_value => \$verbose,
62 description => 'verbose desc.',
63 arg_description => 'verbose arg desc.' }
64
65 Of those keys only long_name, arg_type, and arg_value are required. So
66 this is a valid option entry too:
67
68 { long_name => 'package-names',
69 arg_type => 'string-array',
70 arg_value => \$package_names }
71
72 For convenience, option entries can also be specified as array
73 references containing long_name, short_name, arg_type, and arg_value:
74
75 [ 'filenames', 'f', 'filename-array', \$filenames ]
76
77 If you don't want an option to have a short name, specify undef for it:
78
79 [ 'filenames', undef, 'filename-array', \$filenames ]
80
81 $context->add_group ($group)
82 • $group (Glib::OptionGroup)
83
84 $context->add_main_entries ($entries, $translation_domain)
85 • $entries (scalar) reference to an array of option entries
86
87 • $translation_domain (string)
88
89 boolean = $context->get_help_enabled
90 $context->set_help_enabled ($help_enabled)
91 • $help_enabled (boolean)
92
93 boolean = $context->get_ignore_unknown_options
94 $context->set_ignore_unknown_options ($ignore_unknown)
95 • $ignore_unknown (boolean)
96
97 optiongroup = $context->get_main_group
98 $context->set_main_group ($group)
99 • $group (Glib::OptionGroup)
100
101 boolean = $context->parse
102 This method works directly on @ARGV.
103
104 May croak with a Glib::Error in $@ on failure.
105
106 $group->set_translate_func ($func, $data=undef)
107 • $func (scalar)
108
109 • $data (scalar)
110
111 $group->set_translation_domain ($domain)
112 • $domain (string)
113
115 enum Glib::OptionArg
116 • 'none' / 'G_OPTION_ARG_NONE'
117
118 • 'string' / 'G_OPTION_ARG_STRING'
119
120 • 'int' / 'G_OPTION_ARG_INT'
121
122 • 'callback' / 'G_OPTION_ARG_CALLBACK'
123
124 • 'filename' / 'G_OPTION_ARG_FILENAME'
125
126 • 'string-array' / 'G_OPTION_ARG_STRING_ARRAY'
127
128 • 'filename-array' / 'G_OPTION_ARG_FILENAME_ARRAY'
129
130 • 'double' / 'G_OPTION_ARG_DOUBLE'
131
132 • 'int64' / 'G_OPTION_ARG_INT64'
133
134 flags Glib::OptionFlags
135 • 'hidden' / 'G_OPTION_FLAG_HIDDEN'
136
137 • 'in-main' / 'G_OPTION_FLAG_IN_MAIN'
138
139 • 'reverse' / 'G_OPTION_FLAG_REVERSE'
140
141 • 'no-arg' / 'G_OPTION_FLAG_NO_ARG'
142
143 • 'filename' / 'G_OPTION_FLAG_FILENAME'
144
145 • 'optional-arg' / 'G_OPTION_FLAG_OPTIONAL_ARG'
146
147 • 'noalias' / 'G_OPTION_FLAG_NOALIAS'
148
150 Glib, Glib::Boxed
151
153 Copyright (C) 2003-2011 by the gtk2-perl team.
154
155 This software is licensed under the LGPL. See Glib for a full notice.
156
157
158
159perl v5.34.0 2022-01-21 Glib::OptionGroup(3)