#!/usr/bin/env ruby require 'gli' require 'bookingit' include GLI::App include FileUtils program_desc 'Manage a bookingit book' version Bookingit::VERSION desc 'Set up a new book' arg_name 'dir (defaults to .)' command :init do |c| c.action do |global_options,options,args| dir = args.shift || "." chdir dir do File.open('config.json','w') do |file| file.puts %{ { "front_matter": "front.md", "main_matter": "main.md", "back_matter": "back.md" } } end File.open("front.md",'w') do |file| file.puts "# Intro Goes Here" end File.open("main.md",'w') do |file| file.puts "# Main stuff here" end File.open("back.md",'w') do |file| file.puts "# Appendeces and whatnot" end end end end desc 'build your book from markdown files' arg_name '[output_dir]' command :build do |c| c.desc "Use cache for code samples and console sessions" c.default_value true c.switch :cache c.action do |global_options,options,args| config = Bookingit::Config.new(File.read('config.json'),File.expand_path('.')) config.cache = options[:cache] book = Bookingit::Book.new(config,args.shift) book.render_html! end end pre do |global,command,options,args| true end post do |global,command,options,args| end on_error do |exception| case exception when Bookingit::UnexpectedShellCommandExit $stderr.puts "'#{exception.command}' exited in an unexpected way with exit status #{exception.exit_code}" $stderr.puts "stdout:" $stderr.puts exception.stdout $stderr.puts "stderr:" $stderr.puts exception.stderr false else true end end exit run(ARGV)