Class: Trout::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
# File 'lib/trout/cli.rb', line 12

def initialize(arguments)
  self.arguments     = arguments
  self.option_parser = parse_options
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



10
11
12
# File 'lib/trout/cli.rb', line 10

def arguments
  @arguments
end

#commandObject

Returns the value of attribute command.



10
11
12
# File 'lib/trout/cli.rb', line 10

def command
  @command
end

#fileObject

Returns the value of attribute file.



10
11
12
# File 'lib/trout/cli.rb', line 10

def file
  @file
end

#option_parserObject

Returns the value of attribute option_parser.



10
11
12
# File 'lib/trout/cli.rb', line 10

def option_parser
  @option_parser
end

Class Method Details

.run(arguments) ⇒ Object



6
7
8
# File 'lib/trout/cli.rb', line 6

def self.run(arguments)
  new(arguments).run
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/trout/cli.rb', line 17

def run
  case command
  when 'checkout'
    build_file
    git_url = next_argument
    end_arguments
    file.copy_from(git_url)
  when 'update'
    build_file
    end_arguments
    file.update
  when 'help', nil
    puts option_parser
    if arguments_left?
      puts
      usage_for(next_argument)
    end
  else
    unknown_command(command)
  end
end