Class: ARPM::CLI
- Inherits:
-
Thor
- Object
- Thor
- ARPM::CLI
- Defined in:
- lib/arpm/cli.rb
Instance Method Summary collapse
- #bundle ⇒ Object
- #install(name, version = nil) ⇒ Object
- #list ⇒ Object
- #search(name) ⇒ Object
- #uninstall(name, version = nil) ⇒ Object
- #update(name) ⇒ Object
Instance Method Details
#bundle ⇒ Object
208 209 210 211 212 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 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/arpm/cli.rb', line 208 def bundle # Find the Libfile lib_file = ARPM::Libfile.location if File.exists?(lib_file) # It exists, so get its contents and make an object lib_file = ARPM::Libfile.new(File.open(lib_file).read) # Loop over the dependencies lib_file.dependencies.each do |dependency| name = dependency.keys[0] version = dependency[dependency.keys[0]] # Make sure the package exists package = ARPM::Package.search(name) if package # Is it already installed? if ARPM::List.includes?(name, version) puts "Using #{name}-#{version}" else # No, so install it package.install(version) end else # The package doesn't exist puts "Could not find #{name}".red end end end end |
#install(name, version = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/arpm/cli.rb', line 7 def install(name, version = nil) # Install all the things puts "Searching for packages...".cyan package = ARPM::Package.search(name) if package # Check to see if there actually any releases yet puts "No releases of #{name} yet".red and return unless package.latest_version # Check that the requested version exists if version and !package.versions.include?(version) puts "Version #{version} of #{name} doesn't exist".red return false end # Get the install path path = package.install_path(version) puts "Cloning #{name} into #{path}" # Delete the path if it already exists FileUtils.rm_r(path) if File.exists?(path) # Was the version specified? version = package.latest_version unless version package.install(version) puts "Installed #{name} version #{version}".green.bold else puts "No package named #{name} found".red return false end end |
#list ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/arpm/cli.rb', line 167 def list # Get a list of all the packages packages = ARPM::List.all puts "\nLocal Packages: \n".bold # Loop over them packages.each do |p| name = p.keys.first versions = p[name] # Print them out puts "#{name} (#{versions.join(', ')})".cyan end puts "\n" end |
#search(name) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/arpm/cli.rb', line 190 def search(name) # Search for the package packages = ARPM::Package.search(name, false) if packages # Loop over any results packages.each do |package| puts "#{package.name}-#{package.latest_version}" end else puts "No results".red end end |
#uninstall(name, version = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/arpm/cli.rb', line 50 def uninstall(name, version = nil) if ARPM::List.includes?(name) package = ARPM::Package.new(:name => name, :versions => ARPM::List.versions(name)) versions = package.installed_versions # Was a version specified? if version # Yes it was, is it installed? if versions.include?(version) # Yes it is! Unintstall it package.uninstall(version) puts "#{package.name} version #{version} uninstalled".green.bold else # Nope, it's not installed puts "Version #{version} of #{name} is not installed".red and return end else if package.installed_versions.size > 1 # They've got multiple installed but haven't said which one puts "Please specify a version to uninstall from this list:".red package.installed_versions.each do |v| puts " #{v}" end else version = installed_versions.first # There's only one installed version package.uninstall(version) puts "#{package.name} version #{version} uninstalled".green.bold end end else puts "#{name} is not installed".red and return end end |
#update(name) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/arpm/cli.rb', line 109 def update(name) # Check to see if it is installed? if ARPM::List.includes?(name) # Get the current info package = ARPM::Package.search(name) # Does it exist? if package # Do we have more than one installed version? if package.installed_versions.size > 1 # Yes, ask the user to deal with it puts "#{name} has more than one version installed:".red package.installed_versions.each do |v| puts " #{v}" end puts "Please run" + "arpm install #{name}".bold + "to install the latest one" else # No, just one installed version current_version = package.installed_versions.first # Does this package even need updating? if current_version == package.latest_version # Nope puts "#{name} is already at the most recent version (#{package.latest_version})".red else # Yes, so let's actually fucking do it package.uninstall(current_version) package.install(package.latest_version) puts "#{name} updated to version #{package.latest_version}".green.bold end end else puts "#{name} no longer exists".red and return end else puts "#{name} is not installed yet".red and return end end |