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
1
vote
2 answers

How to check if only one variable of three is set

I would like to restrict the user to inputting (through Getopt::Long) only one value out of a possible three. The values are 'pc-number', 'ip-address', and 'surname'. When there were two values, I was doing the following: if ((!$pc_number and…
unclemeat
  • 5,029
  • 5
  • 28
  • 52
1
vote
1 answer

error handling of getopt in C

I have a question about the error handling of getopt in C: #include #include void showFunction() { printf("show function\n"); } void printHelp() { printf("print help info\n"); } #define HELP 1 #define SHOW_OPTION…
ratzip
  • 1,571
  • 7
  • 28
  • 53
1
vote
1 answer

Long options as static variables for getopt_long

All the examples I've found in the net about the usage of getopt_long (for example this here) declare the struct option with the long options as static. I don't understand why all these examples declare a static variable, I don't see why this…
Pablo
  • 13,271
  • 4
  • 39
  • 59
1
vote
1 answer

Perl Getopt::Declare parameter action not invoked

I use Getopt::Declare in a script but invoking the script and passing -get_ip "test" doesn't do anything i.e. the script executes the "my" statements and getFirstAvailableIP doesn't get called. use Getopt::Declare; use lib…
MemCtrl
  • 131
  • 1
  • 11
1
vote
0 answers

getopt_long() function does not update option_index variable

kindly help. I've gone all over online manuals... yet, no hint whats wrong. The problem is that option_index does not get updated by getopt_long(), thus I'm unable to access proper struct members in form of long_options[option_index].name…
Vlad
  • 63
  • 1
  • 5
1
vote
1 answer

getopt_long_only: how to prevent the next option as being taken as argument for the previous option with "required_argument" flag

for example, I have the structure options as following: struct option options[] = { {"input", required_argument, NULL, OPT_INPUT}, {"flag", no_argument, NULL, OPT_FLAG}, } Now,if a user of the program by mistake omits the input file-name…
Lavya
  • 1,475
  • 2
  • 17
  • 21
1
vote
1 answer

Getting gcc getopt example to accept long arguments?

I'm trying to get the following code to work with the command rectangle –area –length 12 –breadth 34 But I get the error rectangle: invalid option -- r using the short argument option rectangle -a -l 12 -b 34 I get the right answer Area:…
pandoragami
  • 5,387
  • 15
  • 68
  • 116
1
vote
2 answers

Formatting options parsed with Getopt::Long to pass to another program

I am using Getopt::Long to parse options passed to my program. I would like to format these options (after modifying them) to pass to another program. Does Getopt do this, or is there possibly another module that can do this for me? Example: use…
Jeffrey Ray
  • 1,244
  • 2
  • 9
  • 20
1
vote
1 answer

How to use no_argument in getopt_long in?

I am trying to use getopt_long for my code. The optional_argument and required_argument options are working as desired but the no_Argument option is not working properly. This is how I am coding it. struct option long_option[] = { …
lokesharo
  • 305
  • 2
  • 11
1
vote
1 answer

Where does MooseX::Getopt put the unprocessed tokens

I have this fragment package AppOpt; use Moose; use namespace::autoclean; with 'MooseX::Getopt'; has opt1 => (is => 'ro', isa => 'Str', required => 1); has opt2 => (is => 'ro', isa => 'Bool', required =>…
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47
1
vote
2 answers

How to properly use a Getopt::Long to parse optional arguments?

I use Getopt::Long to get command line options for my perl script. I would like to pass an optional argument to it so that I can do something if a value was specified, and something else if the option was called, but no value was passed. The script…
Joel G Mathew
  • 7,561
  • 15
  • 54
  • 86
1
vote
1 answer

Perl Getopt::Long does not seem to modify existing values in array

I'm trying to grab a 3D vector as a single command line input argument using Perl (v5.14.2). After going through the Getopt::Long documentation, I decided to start with this: use Getopt::Long; my @boxSize = (0, 0, 0); GetOptions('box:f{3}' =>…
vishnusr
  • 13
  • 3
1
vote
1 answer

getopt_long preserving default value for optional arg

I'm trying to do some basic option parsing with getopt_long. My specific problem is a default int value being overwritten when the option is not used. I've read through docs and some explanations on getopt but haven't seen anything on preserving…
nflacco
  • 4,972
  • 8
  • 45
  • 78
1
vote
1 answer

Passing arguments into functions using getopt_long in C

I know this topic has probably been done to death, but I've been unable to find anything that made me understand it. I need to enter a value, for instance an IP address, into the command line and pass it to a function. Below is my getopt_long…
youjustreadthis
  • 622
  • 3
  • 9
  • 24
1
vote
2 answers

Getopt::Long missing parameters

I wrote a script that needs to get few arguments from the user, and I encountered a problem while trying to read my script arguments. The script can get the -type for running the functions on one file type or can get the flag -all in order to run on…