Sha256: 9e33acb282aa2f6441ba5da2e02dcbe2defdc8a06c96a056a96d498b89ea0887

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

# -*- coding: utf-8 -*-

require "thor"
require "methan/version"
require "methan/server"


module Methan


  class Console < Thor


    desc "version", "show version"
    def version
      show Methan::VERSION
    end

    desc "new FILENAME", "Create a new memo"
    option :title, type: :string, desc: %q{Title}, aliases: "t"
    def new(filename)
      now = Time.now.strftime("%Y%m%d%H%M%S")
      pwd = Dir::pwd

      filename = "#{filename}.md" unless filename.split(".").last == "md"
      filename = "#{now}_#{filename}"
      filepath = File.join(pwd, filename)

      src = "# #{options[:title] || ''}\n"
      File.open(filepath, "w") do |io|
        io.write(src)
      end
      show "Create memo `#{filename} at #{pwd}`", :green
    end

    desc "server", "Run server"
    option :host, type: :string, desc: "Bind address", aliases: "h", default: ::Methan::Server::DEFAULT_HOST
    option :port, type: :numeric, desc: "Bind port", aliases: "p", default: ::Methan::Server::DEFAULT_PORT
    def server
      ::Methan::Server.rackup(options.dup)
    end


    private

    def show(message, color=nil)
      prefix = case color
               when :red    then "\033[31m"
               when :green  then "\033[32m"
               when :yellow then "\033[33m"
               when :blue   then "\033[34m"
               else ""
               end
      suffix = prefix == "" ? "" : "\033[0m"
      puts "#{prefix}#{message}#{suffix}"
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
methan-0.1.3 lib/methan/console.rb
methan-0.1.2 lib/methan/console.rb
methan-0.1.1 lib/methan/console.rb
methan-0.1.0 lib/methan/console.rb