Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-argv

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-argv

  • 0.1.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ParseArgv version

A command line parser that only needs your help text.

  • Gem: rubygems.org
  • Source: github.com
  • Help: rubydoc.info

Description

Just write the help text for your application and ParseArgv will take care of your command line. It works sort of the other way around than OptParse, where you write a lot of code to get a command line parser and generated help text. ParseArgv simply takes your help text and parses the command line and presents you the results.

You can use ParseArgv for simpler programs just as well as for CLI with multi-level sub-commands (git-like commands). ParseArgv is easy to use, fast and also helps you convert the data types of command line arguments.

Example

The given help text

usage: test [options] <infile> [<outfile>]

This is just a demonstration.

options:
  -f, --format <format>   specify the format
  --verbose               enable verbose mode
  -h, --help              print this help text

will be interpreted as

  • there is a command "test"
  • which requires and argument "infile"
  • optionally accepts an second argument "outfile"
  • accepts an option named "format" when -f or --format are given
  • defines the boolean option "verbose" when --verbose is given
  • defines the boolean option "help" when -h or --help are given

How To Use

Please, see the Gem's help for detailed information, or have a look at the ./examples directory which contains some commands to play around.

The supported help text syntax and the command line interface syntax are described in the syntax help.

In general you just specify the help text and get the parsed command line:

require 'parse-argv'

args = ParseArgv.from <<~HELP
  usage: test [options] <infile> [<outfile>]

  This is just a demonstration.

  options:
    -f, --format <format>   specify the format
    --verbose               enable verbose mode
    -h, --help              print this help text
HELP

args.verbose?
#=> true, when "--verbose" argument was specified
#=> false, when "--verbose" argument was not specified

args[:infile].as(File, :readable)
#=> file name

args.outfile?
#=> true, when second argument was specified
args.outfile
#=> second argument or nil when not specified

Installation

Use Bundler to add ParseArgv in your own project:

Include in your Gemfile:

gem 'parse-argv'

and install it by running Bundler:

bundle

To install the gem globally use:

gem install parse-argv

After that you need only a single line of code in your project to have it on board:

require 'parse-argv'

FAQs

Package last updated on 15 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc