Questions tagged [getopt-long]

Getopt::Long is a command line switch parsing library for Perl. For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options.

The Getopt::Long Perl module is a parser for the POSIX command line switch syntax with GNU extensions. Both the traditional -s single character switches and the longer --longer switches are supported.

For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options. For details, please see here.

190 questions
4
votes
4 answers

In newer Getopt::Long How do I set default optional values

In Perl's Getopt::Long version 2.39 I could use use Getopt::Long qw( :config gnu_getopt ); GetOptions( \my %opts, "codon-view|c:20", # Optional value, default 20 "consensus|C:50", ... ) to indicate that if I use -c the default…
rocky
  • 7,226
  • 3
  • 33
  • 74
4
votes
1 answer

Bundling getopt_long() with my own code?

I have my own C project on github. I want to add long-option support by using GNU getopt_long() (which has it's own git repository). I believe there are 4 ways I can do this: Use a git submodule. Use a git subtree. Import the source of the current…
Paul J. Lucas
  • 6,895
  • 6
  • 44
  • 88
4
votes
1 answer

Error with struct option: array type has incomplete element type

I try to build a function for parsing cmd line. But, when I define the long_options array I get the compile errors: error: array type has incomplete element type error: field name not in record or union initializer error: (near initialization for…
Halona
  • 1,475
  • 1
  • 15
  • 26
4
votes
4 answers

getopt_long vs getopt_long_only

to do a proper Linux/unix styled application, what is the best choice (eg. afaik ls uses getopt_long but for example ffmpeg getopt_long_only). Which one do you recommend? Cheers,
Emanem
  • 41
  • 1
  • 2
4
votes
1 answer

Can Getopt::Long GetOptions generate an error if the same option occurs multiple times?

I have this getopt: GetOptions( GetOptions ("library=s" => \@libfiles); @libfiles = split(/,/,join(',',@libfiles)); "help" => \$help, "input=s" => \$fileordir, "pretty-xml:4" => \$pretty ); Is it possible for…
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
3
votes
5 answers

How can I pass Getopt::Long options to a subroutine that's also an option?

I am trying to setup Getopt::Long to handle the arguments from a configuration script. Here is my starter: #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $config_file = ''; GetOptions ( 'config|c=s' => \$config_file, …
AtomicPorkchop
  • 2,625
  • 5
  • 36
  • 55
3
votes
4 answers

Getopt::Long getting a string with spaces into a variable

I'm making a perl script which uses Getopt::Long to parse command line arguments. However, I have an argument which can accept a string (with spaces). How can I get the whole string into a variable. For example: ./script.pl --string=blah blah blah…
user623990
3
votes
2 answers

Should I expect POSIX to include getopt.h?

According to this, the POSIX library does not include getopt.h. However, I found this in unistd.h: #ifdef __USE_POSIX2 /* Get definitions and prototypes for functions to process the arguments in ARGV (ARGC of them, minus the program name) for …
someguy
  • 7,144
  • 12
  • 43
  • 57
3
votes
1 answer

How to make getopt_long() print nothing when there is error command-line arguments?

I have a program use getopt_get() to parse command line arguments. My code is like this : int opt; int optionIndex; static struct option longOptions[] = { {"help", no_argument, NULL, 'h'}, {"test", no_argument, NULL, 't'}, {0, 0, 0,…
Edure
  • 73
  • 2
  • 8
3
votes
1 answer

getopt_long()/getopt() with duplicated option input

I just got to know both functions. Have been searching internet to learn their usage. Found one thing which is very important to parse the command line option input, but not discussed. Is such a case, if duplicated options are typed in, both…
tao
  • 251
  • 3
  • 13
3
votes
1 answer

How can Perl's Getopt::Long discover arguments with mandatory parameter missing?

In one of my scripts I use the Getopt::Long library. At the beginning of the program I make a call: &GetOptions ('help', 'debug', 'user=s' => \$GetUser); The first two arguments are simple: I discover their existance by checking $opt_help and…
Jasio
  • 275
  • 1
  • 7
3
votes
3 answers

Force use of flags Getopt::Long

Is there a way to force the use of -flags when reading in command-line arguments using Getopt::Long? For example in my current situation: GetOptions('r=s' => \$var1, 'lf=f' => \$var2, 'uf=f' => \$var3, …
AnnaSchumann
  • 1,261
  • 10
  • 22
3
votes
2 answers

Assign values to same variable using Getopt::Long

I was trying to write a small perl script to understand Getopt::Long. Below is the script: #!/usr/bin/perl use strict; use Getopt::Long; my $op_type = ""; my @q_users; GetOptions ( 'query' => $op_type = "query", 'create' => $op_type =…
Fazlin
  • 2,285
  • 17
  • 29
3
votes
2 answers

How to pass both mandatory and optional command line arguments to perl script?

I am using Getopt::Long to pass options to my Perl script. But I want to do something like this : perl myScript mandatoryArgument1 -optionalArgument1=someValue I want the script to throw an error if mandatoryArgument1 is missing. How can this be…
user2524261
  • 109
  • 2
  • 10
3
votes
1 answer

getopt.h missing in aix 7.1

I am having a hard time figuring out how to add getopt.h in my AIX 7.1. I am using the getopt_long function in my code, which I know is in getopt.h instead of unistd.h (which contains getopt()). This code is not compiling in AIX: fatal error:…
Ravindra Mijar
  • 1,282
  • 2
  • 9
  • 17
1 2
3
12 13