Module: TicGitNG::Command
- Defined in:
- lib/ticgit-ng/command.rb,
lib/ticgit-ng/command/new.rb,
lib/ticgit-ng/command/tag.rb,
lib/ticgit-ng/command/help.rb,
lib/ticgit-ng/command/init.rb,
lib/ticgit-ng/command/list.rb,
lib/ticgit-ng/command/show.rb,
lib/ticgit-ng/command/sync.rb,
lib/ticgit-ng/command/state.rb,
lib/ticgit-ng/command/assign.rb,
lib/ticgit-ng/command/attach.rb,
lib/ticgit-ng/command/points.rb,
lib/ticgit-ng/command/recent.rb,
lib/ticgit-ng/command/comment.rb,
lib/ticgit-ng/command/checkout.rb,
lib/ticgit-ng/command/milestone.rb
Defined Under Namespace
Modules: Assign, Attach, Checkout, Comment, Help, Init, List, Milestone, New, Points, Recent, Show, State, Sync, Tag
Constant Summary
collapse
- COMMANDS =
{}
- DOC =
{}
Class Method Summary
collapse
Class Method Details
.default_usage(o) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ticgit-ng/command.rb', line 40
def self.default_usage(o)
o.banner = "Usage: ti COMMAND [FLAGS] [ARGS]"
o.top.append ' ', nil, nil
o.top.append 'The available ticgit commands are:', nil, nil
sorted_doc = DOC.sort_by do |cmds, doc|
cmds.sort_by{|cmd| cmd.size }.last
end
sorted_doc.each do |commands, doc|
command = commands.sort_by{|cmd| cmd.size }.last
o.top.append(" %-32s %s" % [command, doc], nil, nil)
end
end
|
.get(command) ⇒ Object
28
29
30
31
32
|
# File 'lib/ticgit-ng/command.rb', line 28
def self.get(command)
if mod_name = COMMANDS[command]
const_get(mod_name)
end
end
|
.parser(action, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ticgit-ng/command.rb', line 55
def self.parser(action, &block)
OptionParser.new do |o|
o.banner = "Usage: ti #{action} [FLAGS] [ARGS]"
o.base.append ' ', nil, nil
o.base.append 'Common options:', nil, nil
o.on_tail('-v', '--version', 'Show the version number'){
puts TicGitNG::VERSION
exit
}
o.on_tail('-h', '--help', 'Display this help'){
puts o
exit
}
if block_given?
yield(o) if block_given?
unless o.top.list.empty?
if action
o.top.prepend "Options for #{action} command:", nil, nil
o.top.prepend ' ', nil, nil
end
end
end
end
end
|
.register(mod_name, doc, *commands) ⇒ Object
6
7
8
9
10
|
# File 'lib/ticgit-ng/command.rb', line 6
def self.register(mod_name, doc, *commands)
autoload(mod_name, "ticgit-ng/command/#{mod_name.downcase}")
DOC[commands] = doc
commands.each{|cmd| COMMANDS[cmd] = mod_name }
end
|
.usage(action, args) ⇒ Object
34
35
36
37
38
|
# File 'lib/ticgit-ng/command.rb', line 34
def self.usage(action, args)
option_parser = parser(action, &method(:default_usage))
option_parser.parse!(args)
option_parser
end
|