Class: Blocklist::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/blocklist/cli.rb

Constant Summary collapse

COMMANDS =
%w[add list toggle help]

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



6
7
8
9
10
11
12
13
# File 'lib/blocklist/cli.rb', line 6

def initialize(argv)
  @argv = argv
  @bl = Blocklist.new
  @bl.parse(File.read('/etc/hosts'))
  @dry_run = !@argv.delete('-d').nil?
  @quiet = !@argv.delete('-q').nil?
  @command = @argv.shift || 'help'
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
# File 'lib/blocklist/cli.rb', line 15

def run
  if COMMANDS.include? @command
    self.send(@command)
  else
    help "Command unknown: '#{@command}'"
  end
end