Class: Omnizip::Commands::ArchiveExtractCommand
- Inherits:
-
Object
- Object
- Omnizip::Commands::ArchiveExtractCommand
- Defined in:
- lib/omnizip/commands/archive_extract_command.rb
Overview
Command to extract .7z archives to a directory.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ArchiveExtractCommand
constructor
Initialize archive extract command with options.
-
#run(archive_file, output_dir = nil) ⇒ void
Execute the archive extract command.
Constructor Details
#initialize(options = {}) ⇒ ArchiveExtractCommand
Initialize archive extract command with options.
28 29 30 |
# File 'lib/omnizip/commands/archive_extract_command.rb', line 28 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/omnizip/commands/archive_extract_command.rb', line 23 def @options end |
Instance Method Details
#run(archive_file, output_dir = nil) ⇒ void
This method returns an undefined value.
Execute the archive extract command.
37 38 39 40 41 42 43 44 45 46 47 48 49 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 |
# File 'lib/omnizip/commands/archive_extract_command.rb', line 37 def run(archive_file, output_dir = nil) validate_input(archive_file) # Default to current directory if not specified output_dir ||= "." output_dir = File.(output_dir) verbose = [:verbose] || false patterns = Array([:pattern]) if [:pattern] excludes = Array([:exclude]) if [:exclude] regex = [:regex] if verbose CliOutputFormatter.verbose_puts( "Extracting archive: #{archive_file}", true, ) CliOutputFormatter.verbose_puts( "Output directory: #{output_dir}", true, ) if patterns CliOutputFormatter.verbose_puts( "Include patterns: #{patterns.join(', ')}", true, ) end if excludes CliOutputFormatter.verbose_puts( "Exclude patterns: #{excludes.join(', ')}", true, ) end if regex CliOutputFormatter.verbose_puts( "Regex pattern: #{regex}", true, ) end end start_time = Time.now file_count = if patterns || excludes || regex extract_with_patterns(archive_file, output_dir, verbose) else extract_archive(archive_file, output_dir, verbose) end elapsed = Time.now - start_time if verbose puts "" puts "Extraction completed successfully" puts "Files extracted: #{file_count}" puts "Time elapsed: #{elapsed.round(2)}s" else puts "Extracted #{file_count} file(s) to: #{output_dir}" end end |