getopts | Node.js CLI options parser | Command Line Interface library

 by   jorgebucaran JavaScript Version: 2.3.0 License: MIT

kandi X-RAY | getopts Summary

kandi X-RAY | getopts Summary

getopts is a JavaScript library typically used in Utilities, Command Line Interface, Nodejs applications. getopts has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can install using 'npm i getopts-compat' or download it from GitHub, npm.

Node.js CLI options parser
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              getopts has a low active ecosystem.
              It has 630 star(s) with 23 fork(s). There are 13 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 5 open issues and 15 have been closed. On average issues are closed in 55 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of getopts is 2.3.0

            kandi-Quality Quality

              getopts has 0 bugs and 0 code smells.

            kandi-Security Security

              getopts has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              getopts code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              getopts is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              getopts releases are available to install and integrate.
              Deployable package is available in npm.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of getopts
            Get all kandi verified functions for this library.

            getopts Key Features

            No Key Features are available at this moment for getopts.

            getopts Examples and Code Snippets

            No Code Snippets are available at this moment for getopts.

            Community Discussions

            QUESTION

            shell: default values for varargs ($@)
            Asked 2021-May-31 at 15:56

            So I'm writing a shell-script that takes optional arguments (parsing them with getopts and what not; but that doesn't really matter here).

            The user (of the script) is supposed to pass some paths as arguments, which are then processed by some workhorse utilitiy. Of course the paths may contain spaces, so I'm passing the args on with double-quotes ("$@"), along with numerous other flags:

            something like this:

            ...

            ANSWER

            Answered 2021-May-31 at 08:28

            If you have control over how default_paths gets set in your script, then you can just use set to assign the paths as positional arguments

            Source https://stackoverflow.com/questions/67770049

            QUESTION

            Why isn't bash interpreting the passed argument?
            Asked 2021-May-12 at 15:05

            I am attempting to pass an argument via getopts which is a file, ie ./file.txt or file.txt. The problem is, a function that is using the getopts arg isn't interpreting it properly, and shows as an empty arg when debugging. Code shown below:

            ...

            ANSWER

            Answered 2021-May-12 at 14:46

            You failed to declare either -t or -p as taking an argument, so OPTARG isn't set for either option.

            getopts optstring name [args]

            getopts is used by shell procedures to parse positional parameters. optstring contains the option characters to be recognized; if a character is followed by a colon, the option is expected to have an argument, which should be separated from it by white space.

            A correct call to getopts would be

            Source https://stackoverflow.com/questions/67505782

            QUESTION

            "Invalid Argument" Message when sending post for Pushover API
            Asked 2021-Mar-31 at 13:03

            we're currently using pushover, to send messages to our Servicedesk, when our Monitoring finds Errors within our systems.

            Our system collects the data, creates a message, and then sends the needed arguments to a perl script:

            ...

            ANSWER

            Answered 2021-Mar-31 at 13:03

            IT seems that Pushover migrated their API to different IP addresses in order to counteract a DDoS attack on it.

            Since our firewall was only configured to allow traffic to the old addresses, our System was unable to send messages to the IP.

            Why LWP::Useragent flagged this as "invalid arguments" is currently beyond me, but the problem at hand is currently solved.

            Source https://stackoverflow.com/questions/66886496

            QUESTION

            Bash 4.2.46 getopts concatenated short options and resetting OPTIND during processing leads to an infinite loop: How can this be remedied in Bash?
            Asked 2021-Mar-29 at 23:49

            I'm using the following Bash version in a up-to-date CentOS 7 VM:

            GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

            The following code performs as expected (take note of -x -y):

            ...

            ANSWER

            Answered 2021-Mar-29 at 23:49

            How can this be remedied in Bash?

            Well, by patching the sources. But I wouldn't like to do it, I believe the current behavior is the right one.

            You could add an additional function to getopt.c and expose it via some special variable in variables.c that would allow manipulating getopts internal state.

            Or even simpler - I see getopts.def loadable builtin which you could patch to add some additional option to serialize/deserialize getopts state.

            And you can also provide your own implementation of getopts as a bash function with your custom semantics and custom state serializer/deserializer.

            Can anyone shed any light on

            From posix getopts:

            If the application sets OPTIND to the value 1, a new set of parameters can be used: either the current positional parameters or new arg values. Any other attempt to invoke getopts multiple times in a single shell execution environment with parameters (positional parameters or arg operands) that are not the same in all invocations, or with an OPTIND value modified to be a value other than 1, produces unspecified results.

            From that we know:

            The behavior you are seeing is documented - setting OPTIND=1 as $OPTIND is equal to 1 resets getopt(), which results in endless loop, as one would expect. Except for that, bash documentation does not specify what should happen when you modify OPTIND. Do not do it. Your expectation that setting OPTIND to custom value will affect getopts in specific ways is not based on anything. It will not.

            resolve this one issue when writing my wrapper to allow for partial argument/nested getopts handling?

            If you are writing your own argument parsing module, do not use getopts and do not depend on undefined, unspecified nor implementation defined behavior. I suggest to do it the same way GNU getopt does - produce a shell source-able string in separate sub-process, instead of relying on global variables OPT* and contributing to spaghetti code.

            Do not nest getopts, it is not re-entrant and there is no way to affect it's internal state and it uses global variables. getopts sets OPTIND, it is not required to read it, except for the case when OPTIND is reset to 1, in which case getopts is reset. Any other value may just be ignored. Just call one getopts after another.

            Source https://stackoverflow.com/questions/66862735

            QUESTION

            send an hyphened/double-hyphened argument to getopts
            Asked 2021-Mar-29 at 04:58

            I'm using getopts to get optional arguments in a shell script, and then I use them to run another script. one of the arguments I'd like to send to the other program is an optional argument (e.g --conf).

            but when I'm sending it to getopts i get these error messages:

            ...

            ANSWER

            Answered 2021-Mar-29 at 04:54

            Got it! After printing the args as @user1934428 suggested, I've figured out that the last argument is available to the script but not to getopts.

            I've tried to understand why and it hit me, a colon is missing after the 'o'!

            Instead of while getopts 'p:o' OPTION it should be while getopts 'p:o:' OPTION

            as noted in getopts man page:

            if a letter is followed by a colon, the option is expected to have an argument, or group of arguments, which must be separated from it by white space.

            Note: with the information above I fixed the issue and getopts got the last argument, though it parsed it by spaces, even though it was quoted. It because i sent arguments to main function like this main $@ when i shouldv'e quoted it like this main "$@".

            Source https://stackoverflow.com/questions/66795526

            QUESTION

            Bash getopts option with another
            Asked 2021-Mar-26 at 21:15

            My current Bash script looks like in the following. So far it's working except I have no idea how to make it so the two options -f and -o work together:

            • the -o FILE option to display the most relevant information in a file passed as an argument (if the file does not exist an error message must be displayed)
            • the option -f KEYWORD to display the lines containing the KEYWORD to from a file. This option must be used with the -o option

            Thank you for any input

            ...

            ANSWER

            Answered 2021-Mar-26 at 20:09

            Try this: while processing commnand line options, just collect variables. Only do things with those variables after the options are parsed.

            Source https://stackoverflow.com/questions/66823238

            QUESTION

            How to getopts after $1 in bash
            Asked 2021-Mar-26 at 12:00

            I want to run the script as ./script speed -a some_value -b some_value also ./script accuracy -a some_value -b some_value

            What I tried is

            ...

            ANSWER

            Answered 2021-Mar-26 at 05:48

            I don't think you want the outer loop (while [ -n "$1" ]; do), unless you want to be able to process multiple subcommands in a single run. That is, do you want this:

            Source https://stackoverflow.com/questions/66811389

            QUESTION

            Is there a way in bash script to have an option to give an argument but it shouldn't a must?
            Asked 2021-Mar-19 at 11:06

            I have a scenario where i would like to assign an option a default value but a user can decide to give it another argument:

            Here is an example

            ...

            ANSWER

            Answered 2021-Mar-19 at 10:12

            Is there a way in bash script to have an option to give an argument but it shouldn't a must?

            Yes, there is a way.

            getopts does not supports optional arguments. So... you can:

            • roll your own bash library for parsing arguments or
            • use another tool that has support for optional arguments.

            A common tool is getopt that should be available on any linux.

            Source https://stackoverflow.com/questions/66705807

            QUESTION

            Getopts in bash script with sub-arguments
            Asked 2021-Mar-11 at 17:36

            I would like to be able to run a script like this ( with sub-arguments ): I need to be able to use short and long options

            ./myscript.sh -u myname --delete-config --delete-data

            ./myscript.sh -a myname ..........................

            ./myscript.sh -h

            Actually i have :

            ...

            ANSWER

            Answered 2021-Mar-11 at 17:36

            Not working solution, it only works in this case, not with 3 sub parameters

            Thanks to Philippe for his comment : Let me know if you think it's not ok, or purpose better and a confirm as answer :)

            Source https://stackoverflow.com/questions/66586372

            QUESTION

            Changing variable in function dependant on getopts flag bash
            Asked 2021-Feb-11 at 01:28

            I have a bash script that finds connected devices and logs the serial port output to a file. I am using getopts to choose the method of logging. Two of the functions are the same except for one line. I would like to change it to a single function with a variable for the single line that is different (my attempt is below) but have had no success. How can I do this with getopts? Many thanks.

            ...

            ANSWER

            Answered 2021-Feb-11 at 01:28

            I changed a couple things, because I realized that explaining all little details in comments would be too long.

            Here is the code:

            Source https://stackoverflow.com/questions/66106049

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install getopts

            You can install using 'npm i getopts-compat' or download it from GitHub, npm.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/jorgebucaran/getopts.git

          • CLI

            gh repo clone jorgebucaran/getopts

          • sshUrl

            git@github.com:jorgebucaran/getopts.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Command Line Interface Libraries

            ohmyzsh

            by ohmyzsh

            terminal

            by microsoft

            thefuck

            by nvbn

            fzf

            by junegunn

            hyper

            by vercel

            Try Top Libraries by jorgebucaran

            hyperapp

            by jorgebucaranJavaScript

            fisher

            by jorgebucaranShell

            nvm.fish

            by jorgebucaranShell

            superfine

            by jorgebucaranJavaScript

            colorette

            by jorgebucaranJavaScript