Commit 2ef35076 authored by Damian Montero's avatar Damian Montero Committed by GitHub

Merge pull request #1079 from jam7/crew-with-docopt

Change crew to accept multiple arguments by using docopt
parents 9056f537 ff7b82aa
......@@ -6,8 +6,29 @@ require 'digest/sha2'
require 'json'
require 'fileutils'
@command = ARGV[0]
@pkgName = ARGV[1]
# Constants definitions
DOC = <<DOCOPT
Chromebrew - Package manager for Chrome OS http://skycocker.github.io/chromebrew/
Usage:
#{__FILE__} build [-k|--keep] <name>...
#{__FILE__} download <name>...
#{__FILE__} help [<command>]
#{__FILE__} install [-k|--keep] [-s|--build-from-source] <name>...
#{__FILE__} remove <name>...
#{__FILE__} search [-v|--verbose] [<name>...]
#{__FILE__} update
#{__FILE__} upgrade [-k|--keep] [-s|--build-from-source] [<name>...]
#{__FILE__} whatprovides <name>...
-k --keep Keep extracted files as is.
-s --build-from-source Build from source even if pre-compiled binary exists
-v --verbose Show extra information.
-h --help Show this screen.
version 0.4.3
DOCOPT
ARCH = `uname -m`.strip
ARCH_LIB = if ARCH == 'x86_64' then 'lib64' else 'lib' end
......@@ -43,9 +64,25 @@ else
ENV["XZ_OPT"] = ENV["CREW_XZ_OPT"]
end
USER = `whoami`.chomp
# Add lib to LOAD_PATH
$LOAD_PATH.unshift "#{CREW_LIB_PATH}lib"
USER = `whoami`.chomp
# Parse arguments using docopt
require 'docopt'
begin
args = Docopt::docopt(DOC)
rescue Docopt::Exit => e
puts e.message
exit 1
end
@opt_keep = args["--keep"]
@opt_verbose = args["--verbose"]
@opt_src = args["--build-from-source"]
# colorization
class String
......@@ -168,14 +205,14 @@ def regexp_search(pkgName)
results = Dir["#{CREW_LIB_PATH}packages/*.rb"].sort \
.select { |f| File.basename(f, '.rb') =~ Regexp.new(pkgName, true) } \
.collect { |f| File.basename(f, '.rb') } \
.each { |f| print_package(f, ARGV[2] == "extra") }
.each { |f| print_package(f, @opt_verbose) }
if results.empty?
Find.find ("#{CREW_LIB_PATH}packages/") do |packageName|
if File.file? packageName
package = File.basename packageName, '.rb'
search package, true
if ( @pkg.description =~ /#{pkgName}/i )
print_package(package, ARGV[2] == "extra")
print_package(package, @opt_verbose)
results.push(package)
end
end
......@@ -292,8 +329,6 @@ end
def upgrade
if @pkgName
search @pkgName
currentVersion = nil
@device[:installed_packages].each do |package|
if package[:name] == @pkg.name
......@@ -501,7 +536,7 @@ def resolve_dependencies_and_install
abort "#{@pkg.name} failed to install: #{e.to_s}".lightred
ensure
#cleanup
unless ARGV[2] == 'keep'
unless @opt_keep
Dir.chdir CREW_BREW_DIR do
system "rm -rf *"
system "mkdir dest" #this is a little ugly, feel free to find a better way
......@@ -643,7 +678,7 @@ def resolve_dependencies_and_build
abort "#{@pkg.name} failed to build: #{e.to_s}".lightred
ensure
#cleanup
unless ARGV[2] == 'keep'
unless @opt_keep
Dir.chdir CREW_BREW_DIR do
system "rm -rf *"
system "mkdir dest" #this is a little ugly, feel free to find a better way
......@@ -741,62 +776,80 @@ def remove (pkgName)
end
case @command
when "help"
if @pkgName
help @pkgName
else
puts "Usage: crew help [command]"
help nil
end
when "search"
if @pkgName
regexp_search @pkgName
else
list_packages
end
when "whatprovides"
if @pkgName
whatprovides @pkgName
else
help "whatprovides"
def build_command (args)
args["<name>"].each do |name|
@pkgName = name
search @pkgName
resolve_dependencies_and_build
end
when "download"
if @pkgName
end
def download_command (args)
args["<name>"].each do |name|
@pkgName = name
search @pkgName
download
end
end
def help_command (args)
if args["<command>"]
help args["<command>"]
else
help "download"
puts "Usage: crew help [command]"
help nil
end
when "update"
update
when "upgrade"
upgrade
when "install"
if @pkgName
end
def install_command (args)
args["<name>"].each do |name|
@pkgName = name
search @pkgName
@pkg.build_from_source = true if @opt_src
resolve_dependencies_and_install
else
help "install"
end
when "build"
if @pkgName
end
def remove_command (args)
args["<name>"].each do |name|
remove name
end
end
def search_command (args)
args["<name>"].each do |name|
regexp_search name
end.empty? and begin
list_packages
end
end
def update_command (args)
update
end
def upgrade_command (args)
args["<name>"].each do |name|
@pkgName = name
search @pkgName
resolve_dependencies_and_build
else
help "build"
@pkg.build_from_source = true if @opt_src
upgrade
end.empty? and begin
upgrade
end
when "remove"
if @pkgName
remove @pkgName
else
help "remove"
end
def whatprovides_command (args)
args["<name>"].each do |name|
whatprovides name
end
when nil
puts "Chromebrew, version 0.4.3"
puts "Usage: crew [command] [package]"
help nil
else
puts "I have no idea how to do #{@command} :(".lightred
help nil
end
def is_command (name)
return false if name =~ /^[-<]/
return true
end
command_name = args.find { |k, v| v && is_command(k) } [0]
function = command_name + "_command"
send(function, args)
Copyright (c) 2012 Vladimir Keleshev <vladimir@keleshev.com>
Blake Williams <code@shabbyrobe.org>
Alex Speller <alex@alexspeller.com>
Nima Johari
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment