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.



13
14
15
16
17
18
# File 'lib/trout/cli.rb', line 13

def initialize(arguments)
  self.arguments       = arguments
  self.file_attributes = {}
  self.option_parser   = parse_options
  self.managed_files   = VersionList.new('.trout')
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#file_attributesObject

Returns the value of attribute file_attributes.



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

def file_attributes
  @file_attributes
end

#managed_filesObject

Returns the value of attribute managed_files.



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

def managed_files
  @managed_files
end

#option_parserObject

Returns the value of attribute option_parser.



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

def option_parser
  @option_parser
end

Class Method Details

.run(arguments) ⇒ Object



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

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

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trout/cli.rb', line 20

def run
  case command
  when 'checkout'
    file_attributes[:filename] = next_argument
    file_attributes[:git_url]  = next_argument
    file = ManagedFile.new(file_attributes)
    end_arguments
    file.checkout
    managed_files << file
  when 'update'
    file = managed_files[next_argument]
    end_arguments
    file.update
    managed_files << file
  when 'help', nil
    puts option_parser
    if arguments_left?
      puts
      usage_for(next_argument)
    end
  else
    unknown_command(command)
  end
end