Class: Blocklist::Cli
- Inherits:
-
Object
- Object
- Blocklist::Cli
- Defined in:
- lib/blocklist/cli.rb
Constant Summary collapse
- COMMANDS =
%w[add list toggle help]
Instance Method Summary collapse
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
- #run ⇒ Object
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
#run ⇒ Object
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 |