Class: Snaptoken::Commands::BaseCommand
- Inherits:
-
Object
- Object
- Snaptoken::Commands::BaseCommand
show all
- Defined in:
- lib/snaptoken/commands/base_command.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args, tutorial) ⇒ BaseCommand
Returns a new instance of BaseCommand.
4
5
6
7
8
9
10
|
# File 'lib/snaptoken/commands/base_command.rb', line 4
def initialize(args, tutorial)
@args = args
@tutorial = tutorial
@git = Snaptoken::Representations::Git.new(@tutorial)
@litdiff = Snaptoken::Representations::Litdiff.new(@tutorial)
parseopts!
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
2
3
4
|
# File 'lib/snaptoken/commands/base_command.rb', line 2
def config
@config
end
|
Class Method Details
.inherited(subclass) ⇒ Object
17
18
19
|
# File 'lib/snaptoken/commands/base_command.rb', line 17
def self.inherited(subclass)
Snaptoken::Commands::LIST << subclass
end
|
.name ⇒ Object
12
|
# File 'lib/snaptoken/commands/base_command.rb', line 12
def self.name; raise NotImplementedError; end
|
.summary ⇒ Object
13
|
# File 'lib/snaptoken/commands/base_command.rb', line 13
def self.summary; raise NotImplementedError; end
|
Instance Method Details
#git_to_litdiff! ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/snaptoken/commands/base_command.rb', line 62
def git_to_litdiff!
@git.load! do |step_num|
print "\r\e[K[repo/ -> Tutorial] Step #{step_num}" unless @opts[:quiet]
end
puts unless @opts[:quiet]
num_steps = @tutorial.num_steps
@litdiff.save! do |step_num|
print "\r\e[K[Tutorial -> doc/] Step #{step_num}/#{num_steps}" unless @opts[:quiet]
end
puts unless @opts[:quiet]
@tutorial.synced!
end
|
#litdiff_to_git! ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/snaptoken/commands/base_command.rb', line 77
def litdiff_to_git!
@litdiff.load! do |step_num|
print "\r\e[K[doc/ -> Tutorial] Step #{step_num}" unless @opts[:quiet]
end
puts unless @opts[:quiet]
num_steps = @tutorial.num_steps
@git.save! do |step_num|
print "\r\e[K[Tutorial -> repo/] Step #{step_num}/#{num_steps}" unless @opts[:quiet]
end
puts unless @opts[:quiet]
@tutorial.synced!
end
|
#needs!(*whats) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/snaptoken/commands/base_command.rb', line 43
def needs!(*whats)
whats.each do |what|
case what
when :config
if @tutorial.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
|
#parseopts! ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/snaptoken/commands/base_command.rb', line 21
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 ⇒ Object
15
|
# File 'lib/snaptoken/commands/base_command.rb', line 15
def run; raise NotImplementedError; end
|
#setopts!(o) ⇒ Object
14
|
# File 'lib/snaptoken/commands/base_command.rb', line 14
def setopts!(o); raise NotImplementedError; end
|