lib/fig/command.rb in fig-0.1.57 vs lib/fig/command.rb in fig-0.1.59

- old
+ new

@@ -1,8 +1,7 @@ require 'rubygems' require 'net/ftp' -require 'log4r' require 'set' require 'fig/environment' require 'fig/figrc' require 'fig/logging' @@ -15,22 +14,26 @@ require 'fig/retriever' require 'fig/statement/configuration' require 'fig/statement/publish' require 'fig/userinputerror' -# This is a breakout of part of this class simply to keep the file size down. +# These are a breakout of parts of this class simply to keep the file size down. + # You will need to look in this file for any stuff related to --list-* options. require 'fig/command/listing' +# You will need to look in this file for any stuff related to loading the +# primary Package object. +require 'fig/command/packageload' + module Fig; end # Main program class Fig::Command include Fig::Command::Listing + include Fig::Command::PackageLoad - DEFAULT_FIG_FILE = 'package.fig' - def run_fig(argv) @options = Fig::Options.new(argv) if not @options.exit_code.nil? return @options.exit_code end @@ -38,11 +41,11 @@ configure() if @options.clean? check_required_package_descriptor('to clean') - @repository.clean(@descriptor.name, @descriptor.version) + @repository.clean(@descriptor) return 0 end if handle_pre_parse_list_options() return 0 @@ -50,26 +53,26 @@ if @options.publishing? return publish() end - get_package() + load_package_object() if @options.listing() handle_post_parse_list_options() elsif @options.get() puts @environment[@options.get()] elsif @options.shell_command @environment.execute_shell(@options.shell_command) do |command| @operating_system.shell_exec command end elsif @descriptor - @environment.include_config( - @package, @descriptor.name, @descriptor.config, @descriptor.version, {}, nil - ) + @environment.include_config(@package, @descriptor, {}, nil) @environment.execute_config( - @package, @descriptor.name, @descriptor.config, nil, [] + @package, + @descriptor, + @options.command_extra_argv || [] ) { |cmd| @operating_system.shell_exec cmd } elsif not @repository.updating? $stderr.puts "Nothing to do.\n" $stderr.puts Fig::Options::USAGE $stderr.puts %q<Run "fig --help" for a full list of commands.> @@ -111,10 +114,19 @@ end return nil end + def check_include_statements_versions?() + return false if @options.suppress_warning_include_statement_missing_version? + + suppressed_warnings = @configuration['suppress warnings'] + return true if not suppressed_warnings + + return ! suppressed_warnings.include?('include statement missing version') + end + def configure() Fig::Logging.initialize_pre_configuration(@options.log_level()) remote_url = derive_remote_url() @@ -137,25 +149,40 @@ File.expand_path(File.join(@options.home(), 'repos')), remote_url, @configuration, nil, # remote_user @options.update?, - @options.update_if_missing? + @options.update_if_missing?, + check_include_statements_versions? ) @retriever = Fig::Retriever.new('.') - # Check to see if this is still happening with the new layers of abstraction. - at_exit { @retriever.save } + at_exit { @retriever.save_metadata() } - @environment = Fig::Environment.new(@repository, @options.reset_environment? ? {} : nil, @retriever) + @environment = prepare_environment @options.non_command_package_statements().each do |statement| @environment.apply_config_statement(nil, statement, nil) end end + def prepare_environment() + environment_variables = nil + if @options.reset_environment? + environment_variables = Fig::OperatingSystem.get_environment_variables({}) + end + + return Fig::Environment.new(@repository, environment_variables, @retriever) + end + + def base_config() + return @options.config() || + @descriptor && @descriptor.config || + Fig::Package::DEFAULT_CONFIG + end + def check_required_package_descriptor(operation_description) if not @descriptor raise Fig::UserInputError.new( "Need to specify a package #{operation_description}." ) @@ -170,104 +197,16 @@ "Cannot specify a package for #{operation_description}." ) end end - def read_in_package_config_file(config_file) - if File.exist?(config_file) - return File.read(config_file) - else - raise Fig::UserInputError.new(%Q<File not found: "#{config_file}".>) - end - end - def remote_operation_necessary?() return @options.updating? || @options.publish? || @options.listing == :remote_packages end - def load_package_config_file_contents() - package_config_file = @options.package_config_file() - - if package_config_file == :none - return nil - elsif package_config_file == '-' - return $stdin.read - elsif package_config_file.nil? - if File.exist?(DEFAULT_FIG_FILE) - return File.read(DEFAULT_FIG_FILE) - end - else - return read_in_package_config_file(package_config_file) - end - - return - end - - def register_package_with_environment_if_not_listing() - return if @options.listing - - register_package_with_environment() - - return - end - - def register_package_with_environment() - if @options.updating? - @package.retrieves.each do |var, path| - @environment.add_retrieve(var, path) - end - end - - @environment.register_package(@package) - @environment.apply_config( - @package, - @options.config() || @descriptor && @descriptor.config() || 'default', - nil - ) - return - end - - def parse_package_config_file(config_raw_text) - if config_raw_text.nil? - @package = Fig::Package.new(nil, nil, '.', []) - return - end - - @package = - Fig::Parser.new(@configuration).parse_package( - nil, nil, '.', config_raw_text - ) - - register_package_with_environment_if_not_listing() - - return - end - - def load_package_file() - config_raw_text = load_package_config_file_contents() - - parse_package_config_file(config_raw_text) - end - - def get_package() - if @descriptor.nil? - load_package_file() - else - # TODO: complain if config file was specified on the command-line. - @package = - @repository.get_package( - @descriptor.name, @descriptor.version, :disable_updating - ) - - register_package_with_environment_if_not_listing() - end - - return - end - def publish() check_required_package_descriptor('to publish') if @descriptor.name.nil? || @descriptor.version.nil? raise Fig::UserInputError.new('Please specify a package name and a version name.') @@ -277,14 +216,16 @@ publish_statements = @options.resources() + @options.archives() + [ Fig::Statement::Configuration.new( - 'default', @options.non_command_package_statements() + nil, + Fig::Package::DEFAULT_CONFIG, + @options.non_command_package_statements() ) ] - publish_statements << Fig::Statement::Publish.new('default','default') + publish_statements << Fig::Statement::Publish.new() else load_package_file() if not @package.statements.empty? publish_statements = @package.statements else @@ -292,29 +233,28 @@ return 1 end end if @options.publish? - Fig::Logging.info "Checking status of #{@descriptor.name}/#{@descriptor.version}..." + Fig::Logging.info "Checking status of #{@descriptor.to_string()}..." - if @repository.list_remote_packages.include?("#{@descriptor.name}/#{@descriptor.version}") - Fig::Logging.info "#{@descriptor.name}/#{@descriptor.version} has already been published." + package_description = + Fig::PackageDescriptor.format(@descriptor.name, @descriptor.version, nil) + if @repository.list_remote_packages.include?("#{package_description}") + Fig::Logging.info "#{@descriptor.to_string()} has already been published." if not @options.force? Fig::Logging.fatal 'Use the --force option if you really want to overwrite, or use --publish-local for testing.' return 1 else Fig::Logging.info 'Overwriting...' end end end - Fig::Logging.info "Publishing #{@descriptor.name}/#{@descriptor.version}." + Fig::Logging.info "Publishing #{@descriptor.to_string()}." @repository.publish_package( - publish_statements, - @descriptor.name, - @descriptor.version, - @options.publish_local? + publish_statements, @descriptor, @options.publish_local? ) return 0 end