class Leg::Commands::BaseCommand
Attributes
config[R]
opts[R]
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/leg/commands/base_command.rb, line 19 def self.inherited(subclass) Leg::Commands::LIST << subclass end
name()
click to toggle source
# File lib/leg/commands/base_command.rb, line 14 def self.name; raise NotImplementedError; end
new(args, config)
click to toggle source
# File lib/leg/commands/base_command.rb, line 6 def initialize(args, config) @args = args @config = config @git = Leg::Representations::Git.new(@config) @litdiff = Leg::Representations::Litdiff.new(@config) parseopts! end
summary()
click to toggle source
# File lib/leg/commands/base_command.rb, line 15 def self.summary; raise NotImplementedError; end
Public Instance Methods
git_to_litdiff!()
click to toggle source
# File lib/leg/commands/base_command.rb, line 68 def git_to_litdiff! tutorial = @git.load! do |step_num| output "\r\e[K[repo/ -> Tutorial] Step #{step_num}" end output "\n" num_steps = tutorial.num_steps @litdiff.save!(tutorial) do |step_num| output "\r\e[K[Tutorial -> doc/] Step #{step_num}/#{num_steps}" end output "\n" @config.synced! end
litdiff_to_git!()
click to toggle source
# File lib/leg/commands/base_command.rb, line 83 def litdiff_to_git! tutorial = @litdiff.load! do |step_num| output "\r\e[K[doc/ -> Tutorial] Step #{step_num}" end output "\n" num_steps = tutorial.num_steps @git.save!(tutorial) do |step_num| output "\r\e[K[Tutorial -> repo/] Step #{step_num}/#{num_steps}" end output "\n" @config.synced! end
needs!(*whats)
click to toggle source
# File lib/leg/commands/base_command.rb, line 45 def needs!(*whats) whats.each do |what| case what when :config if @config.nil? puts "Error: You are not in a leg working directory." exit 1 end when :repo if @litdiff.modified? and @git.modified? puts "Error: doc/ and .leg/repo have diverged!" exit 1 elsif @litdiff.modified? or !@git.exists? litdiff_to_git! end end end end
output(text)
click to toggle source
# File lib/leg/commands/base_command.rb, line 64 def output(text) print text unless @opts[:quiet] end
parseopts!()
click to toggle source
# File lib/leg/commands/base_command.rb, line 23 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/leg/commands/base_command.rb, line 17 def run; raise NotImplementedError; end
setopts!(o)
click to toggle source
# File lib/leg/commands/base_command.rb, line 16 def setopts!(o); raise NotImplementedError; end