lib/devinstall/cli.rb in devinstall-0.2.6 vs lib/devinstall/cli.rb in devinstall-1.0.0

- old
+ new

@@ -1,91 +1,107 @@ require 'devinstall' require 'getopt/long' require 'devinstall/settings' module Devinstall class Cli - # extend self - # make this module a singleton also - # See why + include Utils + def get_config(fnames) fnames.each do |f| (@opt['config'] ||= (File.expand_path(f) if File.exist? f)) and break end @opt['config'] end - def initialize(package) + def initialize(*package) begin @opt = Getopt::Long.getopts( - ['--package', '-p', Getopt::REQUIRED], ['--config', '-c', Getopt::REQUIRED], ['--type', '-t', Getopt::REQUIRED], - ['--env','-e', Getopt::REQUIRED], - ['--verbose', '-v'], - ['--dry-run', '-d'], + ['--env', '-e', Getopt::REQUIRED], + ['--verbose', '-v'], + ['--dry-run', '-d'], ) rescue - puts 'Invalid option in command line' + puts 'Invalid option at command line' help - exit! 1 end #verbose and dry-run $verbose ||= @opt['verbose'] - $dry ||= @opt['dry-run'] + $dry ||= @opt['dry-run'] # get config file - unless get_config(["./devinstall.yml"]) - puts 'You must specify the config file' - exit! 1 # Exit + get_config(["./devinstall.yml", "~/.devinstall.yml"]) + # add packages + @opt['package']=[] # reset the package array because commandline have priority + if package # a package was supplied on command line + package.each { |p| @opt['package'] << p } # now this overrides everything end - # parse config file - Settings.load!(@opt['config']) - # complete from default values - %w"package env type".each { |o| @opt[o] ||= Settings.defaults[o.to_sym] if Settings.defaults[o.to_sym] } - # verify all informations - if package != '' # a packege was supplied on commandline - @opt['package'] = package # this overrides all + #get default packages + if @opt['package'].empty? + config = Devinstall::Settings.new(@opt['config'], nil, @opt['env'], @opt['type']) # Just for pkg :D + @opt['package'] = config.pkg # we DO have accessor end - %w"package type env".each do |k| - unless @opt[k] - puts "You must specify option '#{k}' either as default or in command line" - help - end - end - # create package - @package=Devinstall::Pkg.new(@opt['package']) end - def version - puts "devinstall version #{Devinstall::VERSION}" - puts "pkg-tool version #{Devinstall::VERSION}" - exit! 0 - end - - def help - puts 'Usage:' - puts 'pkg-install command --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment>' - puts 'where command is one of the: build, install, upload, help, version' - exit! 0 - end - def build - @package.build(@opt['type'].to_sym) + if @opt['config'].empty? + exit! 'You must specify the config file' + end + # create package + @opt['package'].each do |package| + pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])) + pk.build + end end def install - @package.build(@opt['type'].to_sym) - @package.install(@opt['env'].to_sym) + if @opt['config'].empty? + exit! 'You must specify the config file' + end + @opt['package'].each do |package| + pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])) + pk.build + pk.install + end end def upload - @package.build(@opt['type'].to_sym) - @package.run_tests(@opt['env'].to_sym) - @package.upload(@opt['env'].to_sym) + if @opt['config'].empty? + exit! 'You must specify the config file' + end + @opt['package'].each do |package| + config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']) + pk=Devinstall::Pkg.new(config) + pk.build + pk.run_tests + pk.upload + end end def test - @package.run_tests(@opt['env'].to_sym) + if @opt['config'].empty? + exit! 'You must specify the config file' + end + @opt['package'].each do |package| + config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']) + pk=Devinstall::Pkg.new(config) + pk.run_tests + end end + def help + puts 'Usage:' + puts 'pkg-tool command [package_name ... ] --config|-c <file> --type|-t <package_type> --env|-e <environment>' + puts 'where command is one of the: build, install, upload, help, version' + exit! "" + end + + def version + puts "devinstall version #{Devinstall::VERSION}" + puts "pkg-tool version #{Devinstall::VERSION}" + exit! "" + end + end end +