Class: Roast::CLI

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/roast/cli.rb,
lib/roast/cli/commands.rb

Defined Under Namespace

Modules: Commands

Constant Summary collapse

<<-BANNER
Usage: roast COMMAND [ARGS]

Description:
  The roast command manages groups/entries in your /etc/hosts file. It
  has a few different commands available:

    list            list the entries in the hosts file          alias: l
    add             adds a new entry to the hosts file          alias: a
    enable          enables a disabled (commented out) entry    alias: e
    enable-group    enables an entire group                     alias: eg
    disable         disables an entry (comments it out)         alias: d
    disable-group   disables an entire group                    alias: dg
    delete          deletes an entry entirely
    delete-group    deletes an enitre group

Examples:
  # list all entires
  > roast list

  # add an entry to the base group
  > roast add 10.0.1.1 something.dev

  # add an entry to the "testing" group
  > roast add testing 127.0.0.1 exampleapp.dev

  # disable all entries with the ip "10.0.1.1"
  > roast disable 10.0.1.1
BANNER

Constants included from Commands

Commands::ALIASES

Instance Method Summary collapse

Methods included from Commands

#add, #confirm, #delete, #delete_group, #disable, #disable_group, #dispatch, #enable, #enable_group, #list

Instance Method Details

#parse_optionsObject

Use OptionParser to parse options, then we remove them from ARGV



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roast/cli.rb', line 36

def parse_options
  @opts = OptionParser.new do |opts|
    opts.banner = BANNER.gsub(/^ {4}/, '')

    opts.separator ''
    opts.separator 'Options:'

    opts.on('-v', 'Print the version') do
      puts Roast::VERSION
      exit
    end

    opts.on( '-h', '--help', 'Display this help.' ) do
      puts opts
      exit
    end
  end

  @opts.parse!
end


57
58
59
60
# File 'lib/roast/cli.rb', line 57

def print_usage_and_exit!
  puts @opts
  exit
end

#runObject

Called from the executable. Parses the command line arguments



63
64
65
66
67
# File 'lib/roast/cli.rb', line 63

def run
  parse_options
  print_usage_and_exit! if ARGV.empty?
  dispatch
end