Archive::Tar::Minitar::Command::CommandCreate

Public Instance Methods

altname() click to toggle source
     # File lib/archive/tar/minitar/command.rb, line 363
363:     def altname
364:       "cr"
365:     end
call(args, opts = {}, ioe = {}) click to toggle source
     # File lib/archive/tar/minitar/command.rb, line 367
367:     def call(args, opts = {}, ioe = {})
368:       argv    = []
369: 
370:       while (arg = args.shift)
371:         case arg
372:         when '--compress', '-z'
373:           opts[:compress] = true
374:         else
375:           argv << arg
376:         end
377:       end
378: 
379:       if argv.size < 2
380:         ioe[:output] << "Not enough arguments.\n\n"
381:         CommandPattern["help"][["create"]]
382:         return 255
383:       end
384: 
385:       output = argv.shift
386:       if '-' == output
387:         opts[:name] = "STDOUT"
388:         output = ioe[:output]
389:         opts[:output] = ioe[:error]
390:       else
391:         opts[:name] = output
392:         output = File.open(output, "wb")
393:         opts[:output] = ioe[:output]
394:       end
395: 
396:       if opts[:name] =~ /\.tar\.gz$|\.tgz$/ or opts[:compress]
397:         output = Zlib::GzipWriter.new(output)
398:       end
399: 
400:       files = []
401:       if argv.include?("--")
402:           # Read stdin for the list of files.
403:         files = ""
404:         files << ioe[:input].read while not ioe[:input].eof?
405:         files = files.split(/\r\n|\n|\r/)
406:         args.delete("--")
407:       end
408: 
409:       files << argv.to_a
410:       files.flatten!
411: 
412:       if opts[:verbose]
413:         watcher = lambda do |action, name, stats|
414:           opts[:output] << "#{name}\n" if action == :dir or action == :file_done
415:         end
416:         finisher = lambda { opts[:output] << "\n" }
417:       elsif opts[:progress]
418:         progress = ProgressBar.new(opts[:name], 1)
419:         watcher = lambda do |action, name, stats|
420:           case action
421:           when :file_start, :dir
422:             progress.title = File.basename(name)
423:             if action == :dir
424:               progress.total += 1
425:               progress.inc
426:             else
427:               progress.total += stats[:size]
428:             end
429:           when :file_progress
430:             progress.inc(stats[:currinc])
431:           end
432:         end
433:         finisher = lambda do
434:           progress.title = opts[:name]
435:           progress.finish
436:         end
437:       else
438:         watcher = nil
439:         finisher = lambda { }
440:       end
441: 
442:       Archive::Tar::Minitar.pack(files, output, &watcher)
443:       finisher.call
444:       0
445:     ensure
446:       output.close if output and not output.closed?
447:     end
help() click to toggle source
     # File lib/archive/tar/minitar/command.rb, line 449
449:     def help
450:       help =     minitar create [OPTIONS] <tarfile|-> <file|directory|-->+Creates a new tarfile. If the tarfile is named .tar.gz or .tgz, then itwill be compressed automatically. If the tarfile is "-", then it will beoutput to standard output (stdout) so that minitar may be piped.The files or directories that will be packed into the tarfile arespecified after the name of the tarfile itself. Directories will beprocessed recursively. If the token "--" is found in the list of filesto be packed, additional filenames will be read from standard input(stdin). If any file is not found, the packaging will be halted.create Options:    --compress, -z  Compresses the tarfile with gzip.
451:     end
name() click to toggle source
     # File lib/archive/tar/minitar/command.rb, line 359
359:     def name
360:       "create"
361:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.