Socket
Book a DemoInstallSign in
Socket

tlopo-cli

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tlopo-cli

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

tlopo-cli

Gem Version Build Status Code Climate Dependency Status Coverage Status

A Library to speed up CLI apps development

Installation

Add this line to your application's Gemfile:

gem 'tlopo-cli'

And then execute:

bundle

Or install it yourself as:

gem install tlopo-cli

Usage

Simple usage:

require 'tlopo/cli'

class Command
  def self.run(opts)
    puts opts
  end
end

cfg = {
  'name' =>  'command',
  'banner' => "My ClI\n    Run my-cli with ARGS\nOPTIONS:\n",
  'class' => 'Command',
  'switches' => [{
    'name' => 'filename',
    'short' => '-f',
    'long' => '--filename <Filename>',
    'desc' => 'Sets filename'
  }]
}

Tlopo::Cli.new(config: cfg).run 

In action:

$ ruby /tmp/my-cli.rb --help
My ClI
    Run my-cli with ARGS
OPTIONS:
    -f, --filename <Filename>        Sets filename
$ ruby /tmp/my-cli.rb  -f /etc/hosts
{"filename"=>"/etc/hosts"}

You can have as many subcommands as you want, options will be parsed.

require 'tlopo/cli'

class Command
  def self.run(opts)
    puts opts
  end
end

class SubCommand1
  def self.run(opts)
    puts opts
  end
end

class SubCommand2
  def self.run(opts)
    puts opts
  end
end

cfg = {
  :globals => true, # This will include the options for each 'parent' command
  :usage => true, # This will add _usage in opts commands/subcommands can print it  if needed
  'name' =>  'command',
  'banner' => "command\nOPTIONS:\n",
  'class' => 'Command',
  'switches' => [{ 'name' => 'arg1', 'short' => '-a', 'long' => '--arg1 <arg1>', 'desc' => 'Sets arg1'}],
  'subcommands' => [
    { 
      'name' =>  'subcommand1',
      'banner' => "Subcommand1\nOPTIONS:\n",
      'class' => 'SubCommand1',
      'switches' => [{ 'name' => 'arg1', 'short' => '-a', 'long' => '--arg1 <arg1>', 'desc' => 'Sets subcommand1 arg1'} ],
      'subcommands' => [
        { 
          'name' =>  'subcommand2',
          'banner' => "Subcommand2\nOPTIONS:\n",
          'class' => 'SubCommand2',
          'switches' => [{ 'name' => 'arg1', 'short' => '-a', 'long' => '--arg1 <arg1>', 'desc' => 'Sets subcommand2 arg1'}]
        }
      ]
    }
  ]
}

Tlopo::Cli.new(config: cfg).run 

In action:

$ ruby /tmp/my-cli.rb -a 1  subcommand1 -a 2  subcommand2 -a 3
{"arg1"=>"3", "_globals"=>{"command"=>{"class"=>"Command", "arg1"=>"1"}, "command::subcommand1"=>{"class"=>"SubCommand1", "arg1"=>"2"}}}

The configuration can also be a yaml or json file:

Tlopo::Cli.new(config_file: './cli-config.yml')

Contributing

  • Fork it ( https://github.com/[my-github-username]/kubeclient/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Test your changes with rake test rubocop, add new tests if needed.
  • If you added a new functionality, add it to README
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

Tests

This library is tested with Minitest. Please run all tests before submitting a Pull Request, and add new tests for new functionality.

Running tests:

rake test

FAQs

Package last updated on 10 Feb 2018

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.