Sha256: 9af532a6f5e2cf69b99f94751add6cf66192c3f010dd0628083e5174a6662b52

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby

$: << "./lib"

require 'readline'

require 'repl'

trap("INT") { }

include RuneBlog::REPL

def get_argv
  return nil if ARGV.size == 0
  cmd = ARGV[0..1].join(" ")
  arg = ARGV[2]
  [cmd, arg]
end

###########

STDOUT.sync = true

cmd, arg = get_argv

if ! RuneBlog.exist?
  print "No blog found. Create new one? (y/n) "
  resp = gets.chomp
  if resp == "y"
    RuneBlog.create_new_blog
  else
    exit
  end
end

@blog = RuneBlog.new

if cmd.nil?   # REPL
  system("tput smcup")  # see: tput rmcup in cmd_quit

  puts red("\n  RuneBlog v #{RuneBlog::VERSION}")
  loop do
    cmd = Readline.readline(red("\nblog> "), true)

    cmd_quit(nil) if cmd.nil?   # ^D
    cmd.chomp!
    next if cmd.empty?   # CR does nothing
    meth, params = RuneBlog::REPL.choose_method(cmd)
    str = send(meth, params)
    puts str unless str.nil?
  end
else  # one command
  file = File.open("/dev/tty")
  STDIN.reopen(file)    # avoid ARGF dumbness
  cmd = ARGV.join(" ")
  meth, params = RuneBlog::REPL.choose_method(cmd)
  str = send(meth, params)
  puts str unless str.nil?
  puts
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
runeblog-0.0.94 bin/blog
runeblog-0.0.93 bin/blog
runeblog-0.0.91 bin/blog
runeblog-0.0.90 bin/blog
runeblog-0.0.89 bin/blog
runeblog-0.0.88 bin/blog
runeblog-0.0.87 bin/blog