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

mini-cli

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-cli

  • 0.6.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Mini Cli

This gem is a lean, easy to use CLI framework with a very small footprint. It provides an easy to use argument parsing, help displaying, minimalistic error handling and some tools like executing external programs and gather their output.

Installation

To use Mini CLI just install the gem with

gem install mini-cli

or include it to you project's gemspec:

gem 'mini-cli'

Sample

A very minimalistic program may look like this sample program:

require 'mini-cli'

include MiniCli

help <<~HELP, %w[TARGET [SOURCE]]
  -n, --name NAME  option requires NAME argument, has shortcut
      --url URL    option requires URL argument
  -s, --switch     option without any argument, has shortcut
      --opt        option without any argument

  This is a sample application only.
HELP

main do |args|
  puts "TARGET: #{args['TARGET']}"
  puts "SOURCE: #{args['SOURCE']}" if args.key?('SOURCE')
  puts "NAME: #{args['NAME']}" if args.key?('NAME')
  puts "URL: #{args['URL']}" if args.key?('URL')
  puts "FILES: #{args['FILES']}" unless args['FILES'].empty?
  puts '--switch was given' if args.key?('switch')
  puts '--opt was given' if args.key?('opt')
end

The sample uses the powerful #help method to generate an argument parser which handles the command line for you. You only need to handle the given Hash parameter (named args in the sample) in the body of your #main block.

Executing the sample with --help or -h will provide following help screen:

Usage: sample [OPTIONS] TARGET [SOURCE]

Valid Options:
-n, --name NAME  option requires NAME argument, has shortcut
    --url URL    option requires URL argument
-s, --switch     option without any argument, has shortcut
    --opt        option without any argument

This is a sample application only.

See the ./samples directory for more sample programs…

FAQs

Package last updated on 26 Nov 2021

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