Class: Jim::CLI
Overview
CLI handles the command line interface for the ‘jim` binary. It is a `Thor` application.
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#force ⇒ Object
Returns the value of attribute force.
-
#jimfile ⇒ Object
Returns the value of attribute jimfile.
-
#jimhome ⇒ Object
Returns the value of attribute jimhome.
Instance Method Summary collapse
- #available(search = nil) ⇒ Object
- #bundle(bundle_name = nil) ⇒ Object
- #compress(bundle_name = nil) ⇒ Object
- #init(dir = nil) ⇒ Object
-
#initialize ⇒ CLI
constructor
create a new instance with the args passed from the command line i.e.
- #install(url, name = false, version = false) ⇒ Object
- #list(search = nil) ⇒ Object
- #pack(dir = nil) ⇒ Object
- #remove(name, version = nil) ⇒ Object
- #resolve ⇒ Object
- #update_jimfile(dir = nil) ⇒ Object
- #vendor(dir = nil) ⇒ Object
- #watch(dir = nil) ⇒ Object
Constructor Details
#initialize ⇒ CLI
create a new instance with the args passed from the command line i.e. ARGV
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jim/cli.rb', line 38 def initialize(*) super if [:version] say "jim #{Jim::VERSION}", :red exit end # set the default jimhome self.jimhome = Pathname.new([:jimhome] || ENV['JIMHOME'] || '~/.jim'). # parse the options self.jimfile = Pathname.new([:jimfile] || 'Jimfile'). self.force = [:force] self.debug = self.class.respond_to?(:debugging) ? self.class.debugging : [:debug] logger.level = Logger::DEBUG if self.debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
9 10 11 |
# File 'lib/jim/cli.rb', line 9 def debug @debug end |
#force ⇒ Object
Returns the value of attribute force.
9 10 11 |
# File 'lib/jim/cli.rb', line 9 def force @force end |
#jimfile ⇒ Object
Returns the value of attribute jimfile.
9 10 11 |
# File 'lib/jim/cli.rb', line 9 def jimfile @jimfile end |
#jimhome ⇒ Object
Returns the value of attribute jimhome.
9 10 11 |
# File 'lib/jim/cli.rb', line 9 def jimhome @jimhome end |
Instance Method Details
#available(search = nil) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/jim/cli.rb', line 147 def available(search = nil) say "Getting list of all available files in\n#{index.directories.join("\n")}" say "Searching for '#{search}'" if search list = index.list(search) say "Available:" print_version_list(list) end |
#bundle(bundle_name = nil) ⇒ Object
95 96 97 |
# File 'lib/jim/cli.rb', line 95 def bundle(bundle_name = nil) make_bundle(bundle_name, false) end |
#compress(bundle_name = nil) ⇒ Object
119 120 121 |
# File 'lib/jim/cli.rb', line 119 def compress(bundle_name = nil) make_bundle(bundle_name, true) end |
#init(dir = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/jim/cli.rb', line 55 def init(dir = nil) dir = Pathname.new(dir || '') jimfile_path = dir + 'Jimfile' template('jimfile', jimfile_path) end |
#install(url, name = false, version = false) ⇒ Object
73 74 75 |
# File 'lib/jim/cli.rb', line 73 def install(url, name = false, version = false) Jim::Installer.new(url, jimhome, :force => force, :name => name, :version => version).install end |
#list(search = nil) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/jim/cli.rb', line 134 def list(search = nil) say "Getting list of installed files in" say("#{installed_index.directories.join(':')}", :yellow) say("Searching for '#{search}'", :yellow) if search list = installed_index.list(search) say "Installed:" print_version_list(list) end |
#pack(dir = nil) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/jim/cli.rb', line 203 def pack(dir = nil) say "Packing the Jimfile for this project" invoke :vendor, [dir] invoke :bundle invoke :compress end |
#remove(name, version = nil) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/jim/cli.rb', line 158 def remove(name, version = nil) say "Looking for files matching #{name} #{version}" files = installed_index.find_all(name, version) if files.length > 0 say "Found #{files.length} matching files" removed = 0 files.each do |filename| do_remove = yes?("Remove #{filename}?", :red) if do_remove say "Removing #{filename}" filename.delete removed += 1 else say "Skipping #{filename}", :yellow end end say "Removed #{removed} files." else say "No installed files matched." end end |
#resolve ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/jim/cli.rb', line 184 def resolve resolved = bundler.resolve! say "Files:" resolved.each do |bundle_name, requirements| say bundle_name, :green say "-----------------------", :green requirements.each do |path, name, version| say [name, version, path].join(" | ") + "\n" end end resolved rescue Jim::Error => e say e., :red end |
#update_jimfile(dir = nil) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/jim/cli.rb', line 241 def update_jimfile(dir = nil) dir = Pathname.new(dir || '') bundler copy_file(dir + 'Jimfile', dir + 'Jimfile.old') create_file(dir + 'Jimfile', bundler.jimfile_to_json) end |
#vendor(dir = nil) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/jim/cli.rb', line 125 def vendor(dir = nil) dir = bundler.vendor!(dir, force) say("Vendored files to #{dir}", :green) rescue Jim::Error => e say e., :red end |
#watch(dir = nil) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/jim/cli.rb', line 213 def watch(dir = nil) require 'listen' run_update = lambda {|type, path| unless bundler.bundle_paths.any? {|p| path.include?(p) } say("--> #{path} #{type}") system "jim bundle" end } say "Now watching JS files..." run_update["started", 'Jimfile'] dir ||= Dir.pwd Listen.to(File.(dir), :filter => /(\.js$|Jimfile)/) do |modified, added, removed| modified.each do |relative| run_update["changed", relative] end added.each do |relative| run_update["created", relative] end removed.each do |relative| run_update["deleted", relative] end end end |