#!/usr/bin/env ruby # coding: utf-8 require "vintner" require "optparse" require "pp" class String def undent gsub /^.{#{slice(/^ +/).length}}/, '' end end def help puts <<-EOD.undent Usage: vintner [OPTIONS] options: -h, --help\tShow help -v, --version\tShow version commands: init\tCreate Vintner template file install\tInstall formula EOD end def install(brewfile) unless File.exists?(brewfile) puts "Brewfile not found" exit 1 end parser = Vintner::Parser.new parser.parse(brewfile) end OptionParser.new do |opts| opts.on("-h", "--help") do display_help exit end opts.on("-v", "--version") do puts "Vintner #{Vintner::VERSION}" exit end opts.parse!(ARGV) end command, args = ARGV case command when "install" brewfile = args ? File.expand_path(args) : File.join(Dir.pwd, "Brewfile") install(brewfile) when "init" File.open(File.join(Dir.pwd, "Brewfile"), "w") do |f| f.puts <<-EOD.undent # Brewfile is created by Vintner(Winemaker) # https://github.com/oame/vintner brew "nihonshu" brew "sake", :url => "http://example.com" EOD end puts "Finish create Brewfile on current directory!" else brewfile = File.join(Dir.pwd, "Brewfile") install(brewfile) end