Class: Omnizip::Commands::ArchiveCreateCommand
- Inherits:
-
Object
- Object
- Omnizip::Commands::ArchiveCreateCommand
- Defined in:
- lib/omnizip/commands/archive_create_command.rb
Overview
Command to create .7z archives from files and directories.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ArchiveCreateCommand
constructor
Initialize archive create command with options.
-
#run(output_file, *inputs) ⇒ void
Execute the archive create command.
Constructor Details
#initialize(options = {}) ⇒ ArchiveCreateCommand
Initialize archive create command with options.
28 29 30 |
# File 'lib/omnizip/commands/archive_create_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_create_command.rb', line 23 def @options end |
Instance Method Details
#run(output_file, *inputs) ⇒ void
Execute the archive create command.
Execute the archive create command.
Routes through the Archive facade: the handler registry picks each format's writer and applies its option semantics, so this command only translates CLI vocabulary and reports.
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 97 98 99 100 |
# File 'lib/omnizip/commands/archive_create_command.rb', line 46 def run(output_file, *inputs) validate_inputs(output_file, inputs) # Apply profile settings if specified opts = .dup if opts[:profile] first_file = find_first_file(inputs) opts = apply_profile(first_file, opts) end format = (opts[:format] || detect_format(output_file)).to_sym handler_opts = (format, opts) verbose = opts[:verbose] || false announce(output_file, format, handler_opts, opts, verbose) start_time = Time.now Omnizip::Archive.create(output_file, format: format, **handler_opts) do |archive| inputs.each do |input| if File.directory?(input) CliOutputFormatter.verbose_puts( "Adding directory: #{input}", verbose, ) archive.add_directory(input) else CliOutputFormatter.verbose_puts( "Adding file: #{input}", verbose, ) archive.add_file(input) end end end elapsed = Time.now - start_time archive_size = calculate_archive_size(output_file, handler_opts[:volume_size]) if verbose puts "" puts "Archive created successfully" if handler_opts[:volume_size] puts "Total size: #{format_bytes(archive_size)}" puts "Volumes: #{count_volumes(output_file)}" else puts "Archive size: #{format_bytes(archive_size)}" end puts "Time elapsed: #{elapsed.round(2)}s" else puts "Created: #{output_file}" end end |