Class: Vendorificator::CLI

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

Constant Summary collapse

VERBOSITY_LEVELS =
{1 => :quiet, 2 => :default, 3 => :chatty, 9 => :debug}

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.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vendorificator/cli.rb', line 32

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

  if verbosity >= 9
    MiniGit.debug = true
  end

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

  @environment = Vendorificator::Environment.new(
    shell,
    VERBOSITY_LEVELS[verbosity] || :default,
    self.options[:file]
  )

  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.



18
19
20
# File 'lib/vendorificator/cli.rb', line 18

def environment
  @environment
end

#verbosityObject (readonly)

Returns the value of attribute verbosity.



18
19
20
# File 'lib/vendorificator/cli.rb', line 18

def verbosity
  @verbosity
end

Class Method Details

.start(*args) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/vendorificator/cli.rb', line 207

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



189
190
191
192
# File 'lib/vendorificator/cli.rb', line 189

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

#git(command, *args) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/vendorificator/cli.rb', line 168

def git(command, *args)
  modules, git_options = split_git_options(args)
  environment.each_segment(*modules) do |mod|
    unless mod.merged
      say_status 'unmerged', mod.to_s, :red
      next
    end

    actual_args = git_options.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

#info(mod_name) ⇒ Object



117
118
119
120
121
# File 'lib/vendorificator/cli.rb', line 117

def info(mod_name)
  environment.info mod_name, options
rescue MissingVendorfileError
  fail! "Vendorfile not found. Vendorificator needs to run in the directory containing Vendorfile or config/vendor.rb."
end

#install(*modules) ⇒ Object



71
72
73
74
75
# File 'lib/vendorificator/cli.rb', line 71

def install(*modules)
  environment.sync options.merge(:segments => modules)
rescue DirtyRepoError
  fail! 'Repository is not clean.'
end

#listObject



124
125
126
# File 'lib/vendorificator/cli.rb', line 124

def list
  environment.list
end

#log(*args) ⇒ Object



196
197
198
199
# File 'lib/vendorificator/cli.rb', line 196

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

#outdatedObject



129
130
131
# File 'lib/vendorificator/cli.rb', line 129

def outdated
  environment.outdated
end

#pryObject



202
203
204
205
# File 'lib/vendorificator/cli.rb', line 202

def pry
  require 'pry'
  binding.pry
end

#pullObject



136
137
138
139
140
141
142
# File 'lib/vendorificator/cli.rb', line 136

def pull
  environment.pull_all options
rescue DirtyRepoError
  fail! 'Repository is not clean.'
rescue MissingVendorfileError
  fail! "Vendorfile not found. Vendorificator needs to run in the directory containing Vendorfile or config/vendor.rb."
end

#pushObject



146
147
148
149
150
151
152
# File 'lib/vendorificator/cli.rb', line 146

def push
  environment.push options
rescue DirtyRepoError
  fail! 'Repository is not clean.'
rescue MissingVendorfileError
  fail! "Vendorfile not found. Vendorificator needs to run in the directory containing Vendorfile or config/vendor.rb."
end

#statusObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/vendorificator/cli.rb', line 90

def status
  environment.config[:use_upstream_version] = options[:update]
  environment.load_vendorfile

  say_status 'DEPRECATED', 'Using vendor status is deprecated and will be removed in future versions', :yellow
  say_status 'WARNING', 'Git repository is not clean', :red unless environment.clean?

  environment.each_segment(*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
rescue MissingVendorfileError
  fail! "Vendorfile not found. Vendorificator needs to run in the directory containing Vendorfile or config/vendor.rb."
end

#syncObject



61
62
63
64
65
66
67
68
# File 'lib/vendorificator/cli.rb', line 61

def sync
  say_status 'DEPRECATED', 'Using vendor sync is deprecated and will be removed in future versions. Use vendor install or vendor update instead.', :yellow
  environment.sync options.merge(:segments => modules)
rescue DirtyRepoError
  fail! 'Repository is not clean.'
rescue MissingVendorfileError
  fail! "Vendorfile not found. Vendorificator needs to run in the directory containing Vendorfile or config/vendor.rb."
end

#update(*modules) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/vendorificator/cli.rb', line 80

def update(*modules)
  pull if options[:pull]
  environment.sync options.merge(:segments => modules, :update => true)
  push if options[:push]
rescue DirtyRepoError
  fail! 'Repository is not clean.'
end