Sha256: 08ee83b06b3de771f88e6a268c60e2e4eb9dddee618b380cf58c3cb21c22b21f

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby
require 'dirtree'
require 'optparse'
require 'json'
require 'erb'

options = {}
OptionParser.new do |opts|
  opts.banner = 'Usage: dirtree [options]... [file]...'

  opts.on('-v', '--version', 'Print version') do
    puts "Dirtree version #{Dirtree::VERSION}"
    exit
  end

  opts.on('-h', '--help', 'Show this help text') do
    puts opts
    exit
  end

  opts.on('-oFile.html', '--output=File.html', 'Specify a path to write output, if not specified output will be printed to STDOUT') do |value|
    options[:output] = value
  end
end.parse!

files = ARGV.empty? ? STDIN.read.lines : ARGV
files.map!(&:strip)

root = Dirtree::Node.new('/')
files.each { |file| root.insert(file.split('/')) }
templates_dir = File.join(File.dirname(__FILE__), '..', 'templates')
template_file = File.join(templates_dir, 'tree.html.erb')
template = File.read(File.expand_path(template_file))

tree = root.as_json
result = ERB.new(template).result binding

if options.key?(:output)
  File.write(options[:output], result)
else
  puts result
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dirtree-0.1.0 exe/dirtree