#!/usr/bin/env ruby require 'getoptlong' require File.expand_path('../lib/miso/commands', File.dirname(__FILE__)) require File.expand_path('../lib/miso/version', File.dirname(__FILE__)) module Miso class Cli def self.usage puts < [COMMAND OPTIONS] GLOBAL OPTIONS --help, -h Display this message. --version, -v Display version number. COMMANDS new Create a new Miso project. EOF exit 0 end def self.version puts "Miso #{Miso::VERSION}" exit 0 end def self.parse_command_line opts = GetoptLong.new( ['--help', '-h', GetoptLong::NO_ARGUMENT], ['--version', '-v', GetoptLong::NO_ARGUMENT] ) options = {} opts.each do |opt, arg| case opt when '--help' usage when '--version' version else options[opt.sub(/^--/, '')] = arg end end options end def self.main(options) command = ARGV.shift command.nil? && usage case command when 'new' Miso::Commands::New.new(ARGV[0], options).execute else usage end rescue StandardError => e $stderr.puts "ERROR: #{e}" usage end end end Miso::Cli.main(Miso::Cli.parse_command_line)