Class: Vendorificator::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vendorificator/cli.rb', line 24

def initialize(args=[], options={}, config={})
  super

  if self.options[:version]
    say "Vendorificator #{Vendorificator::VERSION}"
    exit
  end

  if self.options[:help] && config[:current_task].name != 'help'
    invoke :help, [ config[:current_task].name ]
    exit
  end

  @environment = Vendorificator::Environment.new(self.options[:file])
  environment.shell = shell

  class << shell
    # Make say_status always say it.
    def quiet?
      false
    end
  end
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
end

Class Method Details

.start(*args) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/vendorificator/cli.rb', line 148

def self.start(*args)
  # Make --git-options always quoted
  if i = ARGV.index('--git-options')
    ARGV[i+1,0] = '--'
  end

  if ENV['FIXTURES_DIR']
    require 'vcr'
    VCR.configure do |c|
      c.cassette_library_dir = File.join(ENV['FIXTURES_DIR'], 'vcr')
      c.default_cassette_options = { :record => :new_episodes }
      c.hook_into :webmock
    end
    VCR.use_cassette(ENV['VCR_CASSETTE'] || 'vendorificator') do
      super(*args)
    end
  else
    super(*args)
  end
end

Instance Method Details

#diff(*args) ⇒ Object



132
133
134
# File 'lib/vendorificator/cli.rb', line 132

def diff(*args)
  invoke :git, %w'diff' + args + %w'@MERGED@ -- @PATH@'
end

#git(command, *args) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vendorificator/cli.rb', line 112

def git(command, *args)
  Vendorificator::Vendor.each(*modules) do |mod|
    unless mod.merged
      say_status 'unmerged', mod.to_s, :red unless options[:only_changed]
      next
    end

    actual_args = args.dup.map do |arg|
      arg.
        gsub('@MERGED@', mod.merged).
        gsub('@PATH@', mod.work_dir)
    end

    say_status command, mod.to_s
    output = environment.git.git(command, *actual_args)
  end
end

#log(*args) ⇒ Object



138
139
140
# File 'lib/vendorificator/cli.rb', line 138

def log(*args)
  invoke :git, %w'log' + args + %w'@[email protected] -- @PATH@'
end

#pryObject



143
144
145
146
# File 'lib/vendorificator/cli.rb', line 143

def pry
  require 'pry'
  binding.pry
end

#pullObject



89
90
91
92
93
94
95
96
97
# File 'lib/vendorificator/cli.rb', line 89

def pull
  ensure_clean!
  remotes = options[:remote] ? options[:remote].split(',') : environment.config[:remotes]
  remotes.each do |remote|
    indent 'remote', remote do
      environment.pull(remote, options)
    end
  end
end

#statusObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vendorificator/cli.rb', line 66

def status
  say_status 'WARNING', 'Git repository is not clean', :red unless environment.clean?
  environment.config[:use_upstream_version] = options[:update]
  Vendorificator::Vendor.each(*modules) do |mod|
    status_line = mod.to_s

    updatable = mod.updatable?
    if updatable
      if updatable == true
        status_line << ' (updatable)'
      else
        status_line << " (updatable to #{updatable.name})"
      end
    end

    say_status( mod.status.to_s.gsub('_', ' '), status_line,
                ( mod.status==:up_to_date ? :green : :yellow ) )
  end
end

#syncObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vendorificator/cli.rb', line 50

def sync
  ensure_clean!
  environment.config[:use_upstream_version] = options[:update]
  Vendorificator::Vendor.each(*modules) do |mod|
    say_status :module, mod.name
    begin
      shell.padding += 1
      mod.run!
    ensure
      shell.padding -= 1
    end
  end
end