<commit_before>note

	description:

		"Eiffel Package Manager"

	copyright: "Copyright (c) 2013, <NAME> and others"
	license: "MIT License"

class EPM

inherit
	KL_SHARED_ARGUMENTS
	KL_SHARED_EXECUTION_ENVIRONMENT
	KL_SHARED_FILE_SYSTEM
	KL_SHARED_OPERATING_SYSTEM
	SHARED_EJSON

create
	make

feature {NONE} -- Initialization

	make
			-- Run the application with options.
		local
			l_package_converter: JSON_EPM_PACKAGE_CONVERTER
			l_parser: AP_PARSER
			l_commands: DS_HASH_TABLE [PROCEDURE [ANY, TUPLE [DS_LIST [detachable STRING]]], STRING]
		do
			create error_handler.make_standard
			create package_reader.make_with_error_handler (error_handler)
			create l_package_converter.make
			package := l_package_converter.object
			json.add_converter (l_package_converter)
			Arguments.set_program_name ("epm")
			create l_parser.make
			l_parser.set_application_description ("Eiffel Package Manager")
			l_parser.set_parameters_description ("<command> where <command> is one of: sync")
			l_parser.parse_arguments
			if attached l_parser.parameters as l_parameters and then attached l_parser.help_option as l_help_option then
				if l_parameters.count < 1 then
					l_help_option.display_help (l_parser)
				else
					create l_commands.make (1)
					l_commands.force_last (agent sync, "sync")
					if attached l_parameters.first as l_first then
						if not l_commands.has (l_first) then
							l_help_option.display_help (l_parser)
						else
							l_commands.item (l_first).call ([l_parameters])
						end
					end
				end
			end
		end

feature -- Basic operations

	sync (some_parameters: DS_LIST [detachable STRING])
			-- Sync (install or update) a package.
		local
			l_dependency, l_dir, l_message, l_script, l_sync_message: STRING
			l_dependencies: DS_LINKED_LIST [detachable STRING]
			l_command: DP_SHELL_COMMAND
			l_clone: GIT_CLONE_COMMAND
			l_checkout: GIT_CHECKOUT_COMMAND
			l_new: BOOLEAN
		do
			l_new := not File_system.is_directory_readable (Eiffel_library_directory)
			if l_new then
				l_sync_message := "Installing"
			else
				l_sync_message := "Updating"
			end
			read_package
			if package_read then
				create l_message.make_empty
				l_message.append_string (l_sync_message)
				l_message.append_string (" package ")
				l_message.append_string (package.name)
				l_message.append_string (" version ")
				l_message.append_string (package.version)
				l_message.append_string ("...")
				error_handler.report_info_message (l_message)
				if attached package.dependencies.new_cursor as l_cursor then
					from
						l_cursor.start
						create l_dependencies.make_equal
						l_dependencies.extend_last (some_parameters)
						if not l_dependencies.is_empty then
							l_dependencies.remove_first
						end
					until
						l_cursor.off
					loop
						l_dependency := l_cursor.key
						if l_dependencies.is_empty or else l_dependencies.has (l_dependency) then
							create l_message.make_empty
							l_message.append_string (l_sync_message)
							l_message.append_string (" dependency ")
							l_message.append_string (l_dependency)
							l_message.append_string ("...")
							error_handler.report_info_message (l_message)
							l_dir := File_system.pathname (eiffel_library_directory, l_dependency)
							if File_system.is_directory_readable (l_dir) then
								sync_update (l_cursor.key, l_cursor.item)
							else
								File_system.create_directory (eiffel_library_directory)
								create l_clone.make_directory (l_cursor.item.repository, l_dir)
								l_clone.execute
								create l_checkout.make (l_cursor.item.branch)
								l_checkout.set_directory (l_dir)
								l_checkout.execute
							end
							if File_system.is_file_readable (File_system.pathname (l_dir, {EPM_PACKAGE_FILE_READER}.Package_file_name)) then
								package_reader.set_directory (l_dir)
								package_reader.read
								if attached package_reader.package as l_package and then attached l_package.environment_variable as l_env then
									Execution_environment.set_variable_value (l_env, File_system.pathname (File_system.cwd, l_dir))
								end
							end
							l_script := File_system.pathname (l_dir, script_file)
							if l_new and File_system.is_file_readable (l_script) then
								create l_command.make (command (l_script))
								l_command.execute
							end
						end
						l_cursor.forth
					end
				end
				if l_new and File_system.is_file_readable (script_file) then
					create l_command.make (command (script_file))
					l_command.execute
				end
				error_handler.report_info_message ("done")
            end
		end

feature {NONE} -- Implementation

	error_handler: EPM_ERROR_HANDLER
			-- Error handler

	package_reader: EPM_PACKAGE_FILE_READER
			-- Package reader<commit_msg>Fixed bug where the script was not executed when running epm sync package<commit_after>note

	description:

		"Eiffel Package Manager"

	copyright: "Copyright (c) 2013, <NAME> and others"
	license: "MIT License"

class EPM

inherit
	KL_SHARED_ARGUMENTS
	KL_SHARED_EXECUTION_ENVIRONMENT
	KL_SHARED_FILE_SYSTEM
	KL_SHARED_OPERATING_SYSTEM
	SHARED_EJSON

create
	make

feature {NONE} -- Initialization

	make
			-- Run the application with options.
		local
			l_package_converter: JSON_EPM_PACKAGE_CONVERTER
			l_parser: AP_PARSER
			l_commands: DS_HASH_TABLE [PROCEDURE [ANY, TUPLE [DS_LIST [detachable STRING]]], STRING]
		do
			create error_handler.make_standard
			create package_reader.make_with_error_handler (error_handler)
			create l_package_converter.make
			package := l_package_converter.object
			json.add_converter (l_package_converter)
			Arguments.set_program_name ("epm")
			create l_parser.make
			l_parser.set_application_description ("Eiffel Package Manager")
			l_parser.set_parameters_description ("<command> where <command> is one of: sync")
			l_parser.parse_arguments
			if attached l_parser.parameters as l_parameters and then attached l_parser.help_option as l_help_option then
				if l_parameters.count < 1 then
					l_help_option.display_help (l_parser)
				else
					create l_commands.make (1)
					l_commands.force_last (agent sync, "sync")
					if attached l_parameters.first as l_first then
						if not l_commands.has (l_first) then
							l_help_option.display_help (l_parser)
						else
							l_commands.item (l_first).call ([l_parameters])
						end
					end
				end
			end
		end

feature -- Basic operations

	sync (some_parameters: DS_LIST [detachable STRING])
			-- Sync (install or update) a package.
		local
			l_dependency, l_dir, l_message, l_script, l_sync_message: STRING
			l_dependencies: DS_LINKED_LIST [detachable STRING]
			l_command: DP_SHELL_COMMAND
			l_clone: GIT_CLONE_COMMAND
			l_checkout: GIT_CHECKOUT_COMMAND
			l_new, l_new_dependency: BOOLEAN
		do
			l_new := not File_system.is_directory_readable (Eiffel_library_directory)
			if l_new then
				l_sync_message := "Installing"
			else
				l_sync_message := "Updating"
			end
			read_package
			if package_read then
				create l_message.make_empty
				l_message.append_string (l_sync_message)
				l_message.append_string (" package ")
				l_message.append_string (package.name)
				l_message.append_string (" version ")
				l_message.append_string (package.version)
				l_message.append_string ("...")
				error_handler.report_info_message (l_message)
				if attached package.dependencies.new_cursor as l_cursor then
					from
						l_cursor.start
						create l_dependencies.make_equal
						l_dependencies.extend_last (some_parameters)
						if not l_dependencies.is_empty then
							l_dependencies.remove_first
						end
					until
						l_cursor.off
					loop
						l_dependency := l_cursor.key
						if l_dependencies.is_empty or else l_dependencies.has (l_dependency) then
							create l_message.make_empty
							l_message.append_string (l_sync_message)
							l_message.append_string (" dependency ")
							l_message.append_string (l_dependency)
							l_message.append_string ("...")
							error_handler.report_info_message (l_message)
							l_dir := File_system.pathname (eiffel_library_directory, l_dependency)
							l_new_dependency := not File_system.is_directory_readable (l_dir)
							if l_new_dependency then
								File_system.create_directory (eiffel_library_directory)
								create l_clone.make_directory (l_cursor.item.repository, l_dir)
								l_clone.execute
								create l_checkout.make (l_cursor.item.branch)
								l_checkout.set_directory (l_dir)
								l_checkout.execute
							else
								sync_update (l_cursor.key, l_cursor.item)
							end
							if File_system.is_file_readable (File_system.pathname (l_dir, {EPM_PACKAGE_FILE_READER}.Package_file_name)) then
								package_reader.set_directory (l_dir)
								package_reader.read
								if attached package_reader.package as l_package and then attached l_package.environment_variable as l_env then
									Execution_environment.set_variable_value (l_env, File_system.pathname (File_system.cwd, l_dir))
								end
							end
							l_script := File_system.pathname (l_dir, script_file)
							if l_new_dependency and File_system.is_file_readable (l_script) then
								create l_command.make (command (l_script))
								l_command.execute
							end
						end
						l_cursor.forth
					end
				end
				if l_new and File_system.is_file_readable (script_file) then
					create l_command.make (command (script_file))
					l_command.execute
				end
				error_handler.report_info_message ("done")
            end
		end

feature {NONE} -- Implementation

	error_handler: EPM_ERROR_HANDLER
			-- Error handler

	package_reader: EPM_PACKAGE_FILE_READER
			-- Package reader
{'fraction_non_alphanumeric': 0.06458658346333854, 'fraction_numerical': 0.0012480499219968799, 'mean_word_length': 3.5337105139085336, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4561922', 'n_tokens_mistral': 4056, 'n_tokens_neox': 3097, 'n_words': 681}