Questions tagged [argp]

An interface in the GNU C library for parsing Unix-style argument vectors.

One source for more information about argp_parse() and the <argp.h> header is The GNU C Library — Argp.

16 questions
12
votes
3 answers

What's the difference between argp and getopt?

I think the title is self explanatory. I am making a program and I was wondering what I should use of the two and why.
Pithikos
  • 18,827
  • 15
  • 113
  • 136
4
votes
1 answer

argp: how to pass argp_state to argp_usage, argp_error, etc...?

Using argp in c++ appears to be missing mutual exclusion that python's argparse handles fairly well. In trying to emulate the same behavior I've noted a problem here. How to pass argp_state to the argp_usage (or other argp helper functions) in main?…
nndhawan
  • 597
  • 6
  • 24
3
votes
2 answers

getopt usage with/without option

I'm writing a simple code making use of *argv[] parameter. I'd like to know whether I can use getopt() function for the following intent. ./myprogram -a PATH ./myprogram PATH The program can either take merely PATH (e.g. /usr/tmp) or take -a option…
2
votes
1 answer

Replace `?` key with `h` key in GNU argp

I'm using the argp.h library to parse command line arguments for my program. I setup it a little and works, but there is just a thing I don't like. When I run my program with --help it show this: -?, --help Give this help list …
Nullndr
  • 1,624
  • 1
  • 6
  • 24
2
votes
1 answer

C argp : Handle option require

I started recently to use argp but i can't find a way to make my option required. I want to see the help when -u (--url) and -w (--wordlist) is not given. Both of them need to be required in order for my programme to work. I look on the internet…
RaiZy_Style
  • 103
  • 10
2
votes
2 answers

GNU argp: How to parse option with only long name?

I want to use argp in my C program to parse command line options. One requirement is that an option does not have a short name (like -f bar) but only a long name (like --foo=bar). My approach so far is to set the key field of the argp_option struct…
ngmir
  • 450
  • 6
  • 26
1
vote
0 answers

Wrong text spacing in help messages with argp.h

About the situation: Greetings, I am working on a project "osfi" in C (with cmake but targeted to be run only on Linux-based OSes), i required a function that parses arguments passed from command line, so i wrote one using the GNU C argp.h. I ended…
user398271
  • 41
  • 3
1
vote
1 answer

GNU argp: Accept optional arguments only with long options

I want to accept a optional argument to an option only with the long form of the option. Assume I define the option -v, --verbose with a optional argument for argp: static struct argp_option opt_global[] = { { "verbose", 'v' , "level",…
Ralf
  • 1,773
  • 8
  • 17
1
vote
1 answer

How to accept a char or string as input

after reading a famous pdf about argp, I wanted to make something with it, but I'm having a problem, in this example: static int parse_opt (int key, char *arg, struct argp_state *state) { switch (key) { case 'd': { …
Diego Francisco
  • 1,650
  • 1
  • 17
  • 31
1
vote
0 answers

How to change --usage output with argp?

I built a program with an config file parser and cli options. My goal was to have this order of priority : CLI options configuration Mandatory configuration file Hardcoded default configuration While parsing my CLI arguments with argp I need to…
MicroCheapFx
  • 392
  • 1
  • 2
  • 15
0
votes
0 answers

How to implement a mandatory single as a parameter with argp?

I am playing around with argp.h in C but I don't manage to recreate the desired behavior for my CLI. What I would like is a syntax similar to, e.g., cryptsetup: Usage: cryptsetup [OPTION...] Let's say, for example, that…
zambowalla
  • 21
  • 4
0
votes
1 answer

Cannot parse flag with argument in argp.h

I'm learning C, and got stuck doing cli parsing with . I want to specify path with -p, --path flags, so I did this: #include "treesome.h" #include #include const char *argp_program_version = "treesome-build…
floatfoo
  • 83
  • 2
  • 8
0
votes
0 answers

how to make argp to ignore unknown argument

Is it possible to make argp ignore unknown parameters? I tried using ARGP_NO_ERRS, but in addition to the fact that, along with the errors, also disables the printouts of the help, the first unknown parameter interrupts the parsing. If, for example,…
mastupristi
  • 1,240
  • 1
  • 13
  • 29
0
votes
1 answer

C - how to allow unrecognized options in Argp or Getopt?

I'm writing FUSE filesystem which uses some arguments. I'd like to pass all unrecognized options to FUSE (because it has its own options). Can I do that using argp or getopt? For now both give me "Unknown option" error.
Lapsio
  • 6,384
  • 4
  • 20
  • 26
0
votes
0 answers

C++: argp and global variables across several files

Argp exposes version and bug information with the global variables const char * argp_program_version and const char * argp_program_bug_address. However, if the source is split across several files it's not at all obvious how to set these variables.…
fionn
  • 57
  • 11
1
2