Sha256: deb650cfb603a57cb2ae1042b494365e5f0f0c3644ebfd08168d1f66e6d98a93

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

#!/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 <<EOF
USAGE: #{File.basename($0)} [GLOBAL OPTIONS] <command> [COMMAND OPTIONS]

GLOBAL OPTIONS
    --help, -h            Display this message.
    --version, -v         Display version number.

COMMANDS
    new <path>            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)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
misosoup-0.1.2 bin/miso
misosoup-0.1.1 bin/miso
misosoup-0.1.0 bin/miso