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
3
votes
1 answer

Bash long options/flags - how to do it?

I am trying to change my working script with getopts to getopt ( long flags ). Below i present my code which is working. getopts 'm:' mode modeValue=$OPTARG getopts 'p:' parameter parameterValue=$OPTARG getopts 'u:'…
adamos
  • 69
  • 8
3
votes
3 answers

How to use Getopt::Long method?

How can I use Getopt::Long method if the input command execution is like this: $ testcmd -option check ARG1 ARG2 ARG3 or $ testcmd ARG1 ARG2 ARG3
Tree
  • 9,532
  • 24
  • 64
  • 83
3
votes
1 answer

getopt_long don't return 0 when have flag set in struct option

I met a problem when using getopt_long in C. As is descripted, in the structure as follows: struct option{ const char *name; int has_arg; int *flag; int val; }; If flag is set, getopt_long should return 0…
SpongeDu
  • 33
  • 3
3
votes
2 answers

command line option used in a module and in the main script

I have a module misc which is used by a few scripts. Each script accept two standard options (-help and -verbose) as well as a bunch of its own ones. So, every scripts now has my ($verbose,$quiet) = (1,0); my $help =…
sds
  • 58,617
  • 29
  • 161
  • 278
2
votes
2 answers

Use Getopt::Long in Perl to get multidimensional data structures

I got this code below to work as I need, but would like to know if there's a better way of doing this without quotes. myScript.pl --filter 'key1 foo bar' --filter 'key2 baz qux' #!/usr/local/bin/perl5.8.8 use warnings; use strict; use…
Wilderness
  • 1,309
  • 2
  • 15
  • 27
2
votes
1 answer

How to access multiple option values from hash specification

use Getopt::Long; GetOptions(\%gOptions, "help", "size=i", "filename=s{2}", ); I am passing options like - --size 200 --filename abc.txt def.txt I tried accessing filename from the hash specification…
Cool Camel
  • 57
  • 6
2
votes
1 answer

Can we use dynamic array data() as a longopts parameter in getopt_long function?

I am trying to create an argument parsing class on C++ that will be using getopt_long function. So basically I want the longopts argument can be created dynamically. This code, that using static array for longopts argument will work: int main(int…
2
votes
1 answer

How can I handle an option made of an arbitrary number with Getopt::Long[::Descriptive]?

I would like to be able to handle options like -1 or -10 similarly to how head or -tail do. In other words, be able to do my_script.pl -10 --some-other-option arguments and be able to retain the value of the -10 option. Right now the only idea…
simone
  • 4,667
  • 4
  • 25
  • 47
2
votes
3 answers

Get optarg as a C++ string object

I am using getopt_long to process command line arguments in a C++ application. The examples all show something like printf("Username: %s\n", optarg) in the processing examples. This is great for showing an example, but I want to be able to actually…
Beau Simensen
  • 4,558
  • 3
  • 38
  • 55
2
votes
1 answer

Ruby GetoptLong modifies ARGV?

The documentation for Ruby's GetoptLong gave me the impression that it would remove the parsed options from ARGV. Here's the passage in question: For example, if -a does not require an argument and -b optionally takes an argument, parsing ’-a one…
Joyce
  • 572
  • 5
  • 11
2
votes
3 answers

Getopts to flag bad options without dash

Getopt::Long::Configure("no_pass_through"); my %opts = (); GetOptions(\%opts, 'opt1=s', 'opt2=s', 'opt3' ); test.pl bad_option_without_dash How do I make getopts flag an error when a bad option is passed…
Jean
  • 21,665
  • 24
  • 69
  • 119
2
votes
2 answers

Perl Getopt::Long supporting spaces for arguments

I have a Perl script, which uses GetOpts long. A command like this is easily handled: automate -action build,deploy -modules chat,email,login What I want to achieve is to allow the user to give spaces between arguments. E.g automate -action build,…
Neeraj
  • 8,408
  • 8
  • 41
  • 69
2
votes
2 answers

Pass Multiple Values to command Line argument and Store it as an array

I am trying to pass Multiple Values to an Command line Argument as -cmd 'cp abc def' 'ls abd/def/ghi' etc ... and wanted to store these individually as an element of an array. I can take this to a string and use split function. i am trying to…
PCM
  • 21
  • 2
2
votes
3 answers

Perl Getopt::Long - use subparameter only for defined parameter

I would like the --import parameter to have a "sub-parameter" that will only work on this parameter, nowhere else. Example: app.pl --import --fresh output: command working app.pl --export output: command working app.pl --export --fresh output:…
J. Doe
  • 71
  • 1
  • 6
2
votes
1 answer

is it possible to use getopt_long to parse arrays of strings similar to command line arguments in a C program?

I am aware that getopt should be used to parse command line arguments, and not strings. However, I am confused by the fact that if I pass it an array of strings that "looks like" the argv variable, getopt_long seems to work, but only the first time…
Sharkovsky87
  • 133
  • 9