class Snaptoken::Commands::BaseCommand
Constants
- ERROR_MSG
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 13 def self.inherited(subclass) Snaptoken::Commands::LIST << subclass end
name()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 8 def self.name; raise NotImplementedError; end
new(args, config)
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 2 def initialize(args, config) @args = args @config = config parseopts! end
summary()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 9 def self.summary; raise NotImplementedError; end
Public Instance Methods
latest_step()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 122 def latest_step steps.last end
needs!(*whats)
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 75 def needs!(*whats) options = whats.pop if whats.last.is_a? Hash options ||= {} yes = Array(whats).flatten.map { |w| [w, true] } no = Array(options[:not]).map { |w| [w, false] } (yes + no).each do |what, v| valid = case what when :config !!@config when :config_sync %w(repo steps).include?(@config[:sync]) when :steps_folder File.exist?(File.join(@config[:path], "steps")) when :steps steps.length > 0 when :repo File.exist?(File.join(@config[:path], "repo")) when :diff File.exist?(File.join(@config[:path], "steps.diff")) when :doc File.exist?(File.join(@config[:path], "doc")) when :doc_out File.exist?(File.join(@config[:path], "doc/html_out")) when :cached_diffs File.exist?(File.join(@config[:path], ".cached-diffs")) when :ftp File.exist?(File.join(@config[:path], "ftp.yml")) else raise NotImplementedError end if valid != v puts "Error: " + ERROR_MSG[what][v.to_s.to_sym] exit! end end end
parseopts!()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 17 def parseopts! parser = OptionParser.new do |o| o.banner = "Usage: leg #{self.class.name} #{self.class.usage}" self.class.summary.split("\n").each do |line| o.separator " #{line}" end o.separator "" o.separator "Options:" setopts!(o) o.on_tail("-h", "--help", "Show this message") do puts o exit end end @opts = {} parser.parse!(@args) rescue OptionParser::InvalidOption, OptionParser::InvalidArgument => e puts "#{e.message}" puts parser.parse("--help") end
run()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 11 def run; raise NotImplementedError; end
setopts!(o)
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 10 def setopts!(o); raise NotImplementedError; end
step_path(step)
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 126 def step_path(step) File.join(@config[:path], "steps", step.folder_name) end
steps()
click to toggle source
# File lib/snaptoken/commands/base_command.rb, line 116 def steps @steps ||= Dir[File.join(@config[:path], "steps/*")].map do |f| Snaptoken::Step.from_folder_name(File.basename(f)) if File.directory?(f) end.compact.sort_by(&:number) end