---
name: "Glib::OptionGroup"
section: "3pm"
platform: "linux"
package: "glib-perl"
version: "1.329.4-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Glib::OptionGroup"
---

# Glib::OptionGroup(3pm)

group of options for command line option parsing

## NAME

Glib::OptionGroup -  group of options for command line option parsing

## SYNOPSIS

```
  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
```

## HIERARCHY

```
  Glib::Boxed
  +----Glib::OptionGroup
```

## 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 ]
```

### $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 a Glib::Error in $@ on failure.

### $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'

## SEE ALSO

Glib, Glib::Boxed

## COPYRIGHT

Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL.  See Glib for a full notice.
