bin/jeckyl in jeckyl-0.2.7 vs bin/jeckyl in jeckyl-0.3.7
- old
+ new
@@ -1,49 +1,47 @@
-#!/usr/bin/env ruby18
+#!/usr/bin/env ruby
#
-# Description
+# Command Line utilities for Jeckyl
#
# Author:: Robert Sharp
-# Copyright:: Copyright (c) 2010 Robert Sharp
+# Copyright:: Copyright (c) 2013 Robert Sharp
# License:: Open Software Licence v3.0
#
# This software is licensed for use under the Open Software Licence v. 3.0
# The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
# and in the file copyright.txt. Under the terms of this licence, all derivative works
# must themselves be licensed under the Open Software Licence v. 3.0
#
#
-# replace this to point to your config class
-# require 'my_jeckyl_configurator'
-require 'rubygems' # want to find classes that might be in gems
+
+require 'rubygems'
+require 'optplus'
+
require 'jeckyl'
require 'jeckyl/errors'
-require 'thor'
-require 'thor/group'
-require 'colored'
-
-
-# the Command Line Interface for jeckyl to allow users to generate
-# config files, generate a simple template or check a config file
-class JeckylCLI < Thor
+class JeckylCli < Optplus::Parser
- default_task :usage
+ usage "action [params] [options]"
- desc "usage", "You are looking at it"
- def usage
- puts "Useful tasks for managing Jeckyl config files."
- puts ""
- help
- puts ""
- puts "See Also:"
- puts " README.md: (see jeckyl readme above)"
- puts " GitHub: https://github.com/osburn-sharp/jeckyl"
- puts " RubyDoc: http://rdoc.info/github/osburn-sharp/jeckyl/frames"
+ description "Useful utilities for Jeckyl configuration files.",
+ "To find out more, type 'jeckyl readme'"
+
+ # before_all
+
+ def options(opts)
+ opts.on('-C', '--class Index', Integer, 'select a class by index') do |i|
+ set_option :klass_index, i
+ end
+ opts.on('-k', '--concat', 'concat all classes, starting with the oldest') do
+ set_option :konkat
+ end
end
- desc "readme", "display the readme file for the gem"
+ # before_actions
+
+ describe "readme", "display the readme file for the gem"
def readme
gem_spec = Gem::Specification.find_by_name('jeckyl')
readme_path = File.join(gem_spec.gem_dir, 'README.md')
File.open(readme_path) do |rfile|
@@ -52,43 +50,49 @@
end
end
end
- desc "list", "list all the config classes involved in a given class"
- def list(cfile)
+ describe "list", "list all the config classes involved in a given class"
+ def list
+ cfile = next_argument_or_error("missing config class")
require cfile
classes = Jeckyl::Options.descendants
display_classes(classes)
rescue LoadError
puts "Error: could not load #{cfile}".red.bold
end
+ help :list, "Show a list of this config class and its ancestors",
+ "This is useful when you have create a config class from a parent class",
+ "in order to include the parent classes' parameters.",
+ "The list is indexed and the index can be used in other actions,",
+ "include 'jeckyl config'."
- desc "config", "generate config file for the given config class"
- method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
- method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
- def config(cfile, my_class_name=nil)
-
+
+ describe "config", "generate config file for the given config class"
+ def config
+ cfile = next_argument_or_error("You must provide a config class")
require cfile # catch LoadError if cfile does not load
- my_class_index = options[:class] || 0
- my_class_index += -1 if my_class_index > 0
+ my_class_index = get_option(:klass_index) || 0
+ my_class_index -= 1 if my_class_index > 0
+ konkat = get_option :konkat
classes = Jeckyl::Options.descendants
- if options[:concat].nil? && classes[my_class_index].nil? then
+ if !konkat && classes[my_class_index].nil? then
$stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
display_classes(classes)
return false
end
$stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
my_classes = []
- if options[:concat] then
+ if konkat then
classes.each_index {|i| my_classes.unshift i}
else
my_classes << my_class_index
end
@@ -98,24 +102,37 @@
puts "#"
puts
classes[ci].generate_config(true)
end
- unless options[:concat] || classes.length == 1
+ unless konkat || classes.length == 1
puts ""
puts "# There are also parameters in:"
classes.each do |klass|
puts "# #{klass.name}"unless klass == classes[my_class_index]
end
end
rescue LoadError
- puts "Error: could not load #{cfile}".red.bold
+ if cfile.nil? then
+ puts "Error: you need to specify a configration file".red.bold
+ else
+ puts "Error: could not load #{cfile}".red.bold
+ end
end
+ help :config, "Outputs a default config file for the given class.",
+ "Use this to create a default file that you can then tailor for",
+ "specific settings. If there is more than one class involved use",
+ "-k to create an output with all the config parameters included.",
+ "Output is to stdout and can easily be redirected to a file as needed."
- desc "klass", "generate a simple class template"
- def klass(name, parent="Jeckyl::Config")
+
+
+ describe "klass", "generate a simple class template"
+ def klass
+ name = next_argument_or_error("missing class name")
+ parent = next_argument_or('Jeckyl::Config')
puts <<EOTXT
# Simple framework for defining Jeckyl options to put into a config hash
module #{name}
@@ -133,17 +150,24 @@
end
end
end
EOTXT
-
+
end
+ help :klass, "Generate a simple class file as a template for defining your",
+ "own parameters. You can also specify a class to inherit if you want to",
+ "pick up additional parameters. Otherwise the parent will default to",
+ "Jeckyl::Config. Alternatives include Jellog::Config and JerbilService::Config."
- desc "check", "check the given config file is valid for the given class"
+ describe "check", "check the given config file is valid for the given class"
def check(klass_file, conf_file)
+ klass_file = next_argument_or_error("missing class name")
+ conf_file = next_argument_or_error("missing config file")
+
require klass_file # catch LoadError if cfile does not load
my_class_index = 0 # assume there is only one
classes = Jeckyl::Options.descendants
@@ -151,36 +175,40 @@
classes[my_class_index].check_config(conf_file)
rescue LoadError
puts "Error: could not load #{cfile}".red
-
+
end
+ help :check, "Use the given class (which must be requirable) and check",
+ "that the given config file is OK or show errors if not.",
+ "Useful way to check that a config file works before using it in earnest."
- desc "markdown", "display the comments from a class in markdown format"
- method_option :class, :aliases=>'-C', :type=>:numeric, :desc=>'select class by index'
- method_option :concat, :aliases=>'-k', :desc=>'concat all classes, starting with the oldest'
- def markdown(cfile)
+
+ describe "markdown", "display the comments from a class in markdown format"
+ def markdown
+ cfile = next_argument_or_error("missing class")
+
require cfile # catch LoadError if cfile does not load
- my_class_index = options[:class] || 0
- my_class_index += -1 if my_class_index > 0
+ my_class_index = get_option(:klass_index) || 0
+ my_class_index -= 1 if my_class_index > 0
+ konkat = get_option :konkat
-
classes = Jeckyl::Options.descendants
- if options[:concat].nil? && classes[my_class_index].nil? then
+ if !konkat && classes[my_class_index].nil? then
$stderr.puts "Index #{my_class_index + 1} is invalid. Please select a valid index".red.bold
display_classes(classes)
return false
end
$stderr.puts "There are #{classes.length} sets of configs, use 'jeckyl list' to list them or -k to generate them all".yellow if classes.length > 1
my_classes = []
- if options[:concat] then
+ if konkat then
classes.each_index {|i| my_classes << i}
else
my_classes << my_class_index
end
@@ -223,11 +251,11 @@
end
puts ""
end
end
- unless options[:concat] || classes.length == 1
+ unless konkat || classes.length == 1
puts ""
puts "## See Also"
puts ""
puts "There are also parameters in:"
puts ""
@@ -238,20 +266,24 @@
rescue LoadError
puts "Error: could not load #{cfile}".red
end
+ help :markdown, "Similar to config but instead of creating the config file itself",
+ "this creates a markdown file that can be used in rdoc to describe the config",
+ "parameters."
- no_tasks do
+
def display_classes(classes)
$stderr.puts "The following classes are available:".green
count = 1
classes.each do |klass|
$stderr.puts " #{count}. #{klass.name}"
count += 1
end
end
- end
+
+
end
-JeckylCLI.start
+JeckylCli.run!
\ No newline at end of file