cli-topic 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clitopic/command/base.rb +19 -12
- data/lib/clitopic/command/clito.rb +35 -5
- data/lib/clitopic/command/help.rb +0 -12
- data/lib/clitopic/helpers.rb +1 -0
- data/lib/clitopic/parser/option_parser.rb +14 -5
- data/lib/clitopic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dd7bf15db7efd2aaa6f731dc05a2da91ad99531
|
4
|
+
data.tar.gz: 30f0feebf43a90dd6c6a5e1d479b31c67d428e41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cfdfdbe05f0f6ae712cb49fe21067d0575400c35b376aadc634ff66b2e32d5bfeefbcf1481e4cbf61ca3f1a1394b44bc56f5b57a11fb6e450653e38c44227f5
|
7
|
+
data.tar.gz: 5df8e9e83e3607f051caa62fc08defcdf5b8e0b2ad890b47c60a7a283327c33f4b3309fef33fe40e41290312755b87e84db93fd6f63e64c9b4a26a991f3aca6c
|
@@ -9,7 +9,7 @@ module Clitopic
|
|
9
9
|
class << self
|
10
10
|
include Clitopic::Parser::OptParser
|
11
11
|
attr_accessor :name, :banner, :description, :hidden, :short_description
|
12
|
-
attr_accessor :arguments, :options
|
12
|
+
attr_accessor :arguments, :options, :inherited_options
|
13
13
|
|
14
14
|
def cmd_options
|
15
15
|
@cmd_options ||= []
|
@@ -19,6 +19,10 @@ module Clitopic
|
|
19
19
|
@banner ||= "Usage: #{Clitopic.name} #{self.fullname} [options]"
|
20
20
|
end
|
21
21
|
|
22
|
+
def inherited_options(*cmds)
|
23
|
+
@inherited_options ||= cmds
|
24
|
+
end
|
25
|
+
|
22
26
|
def short_description
|
23
27
|
if @short_description.nil?
|
24
28
|
if description
|
@@ -98,22 +102,25 @@ module Clitopic
|
|
98
102
|
cmd_defaults = defaults["commands"][self.name]
|
99
103
|
end
|
100
104
|
else
|
105
|
+
|
101
106
|
if defaults.has_key?("topics") && defaults["topics"].has_key?(self.topic.name)
|
102
107
|
cmd_defaults = defaults['topics'][self.topic.name][self.name]
|
103
108
|
topic_opts = defaults['topics'][self.topic.name]['topic_options']
|
109
|
+
load_options(topic_opts)
|
110
|
+
if !cmd_defaults.nil?
|
111
|
+
load_options(cmd_defaults["options"])
|
112
|
+
if cmd_defaults["args"] && !arguments
|
113
|
+
@arguments += Array(cmd_defaults["args"])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
self.inherited_options.each do |cmd|
|
117
|
+
if defaults["topics"].has_key?(self.topic.name)
|
118
|
+
cmd_opts = defaults['topics'][self.topic.name][cmd.to_s]
|
119
|
+
load_options(cmd_opts["options"]) if !cmd_opts.nil?
|
120
|
+
end
|
121
|
+
end
|
104
122
|
end
|
105
123
|
end
|
106
|
-
|
107
|
-
load_options(topic_opts)
|
108
|
-
|
109
|
-
if cmd_defaults.nil?
|
110
|
-
return
|
111
|
-
end
|
112
|
-
|
113
|
-
load_options(cmd_defaults["options"])
|
114
|
-
if cmd_defaults["args"] && !arguments
|
115
|
-
@arguments += Array(cmd_defaults["args"])
|
116
|
-
end
|
117
124
|
end
|
118
125
|
|
119
126
|
def topic(arg=nil)
|
@@ -35,6 +35,9 @@ module Clitopic
|
|
35
35
|
class << self
|
36
36
|
def cmd_opts(cmd, opts)
|
37
37
|
if cmd.cmd_options.size > 0 && (!cmd.hidden || options[:hidden])
|
38
|
+
cmd_comment = "#{cmd.name}$comment"
|
39
|
+
opts[cmd_comment] = {}
|
40
|
+
opts = opts[cmd_comment]
|
38
41
|
opts[cmd.name] = {"options" => {}, "args" => []}
|
39
42
|
cmd.cmd_options.each do |opt|
|
40
43
|
opts[cmd.name]["options"][opt[:name].to_s] = opt[:default]
|
@@ -60,14 +63,16 @@ module Clitopic
|
|
60
63
|
opts['topics'] = {}
|
61
64
|
Clitopic::Topics.topics.each do |topic_name, topic|
|
62
65
|
if (!topic.hidden || options[:hidden])
|
63
|
-
|
64
|
-
opts['topics'][
|
66
|
+
topic_comment = "#{topic_name}$comment"
|
67
|
+
opts['topics'][topic_comment] = {}
|
68
|
+
opts['topics'][topic_comment][topic_name] = {}
|
69
|
+
opts['topics'][topic_comment][topic_name]["topic_options"] = {} if topic.topic_options.size > 0
|
65
70
|
topic.topic_options.each do |opt|
|
66
|
-
opts['topics'][topic_name]["topic_options"][opt[:name].to_s] = opt[:default]
|
71
|
+
opts['topics'][topic_comment][topic_name]["topic_options"][opt[:name].to_s] = opt[:default]
|
67
72
|
end
|
68
73
|
if topic.commands.size > 0
|
69
74
|
topic.commands.each do |c, cmd|
|
70
|
-
cmd_opts(cmd, opts['topics'][topic_name])
|
75
|
+
cmd_opts(cmd, opts['topics'][topic_comment][topic_name])
|
71
76
|
end
|
72
77
|
end
|
73
78
|
end
|
@@ -82,12 +87,37 @@ module Clitopic
|
|
82
87
|
end
|
83
88
|
end
|
84
89
|
puts "write: #{file}"
|
90
|
+
yaml = opts.to_yaml
|
91
|
+
|
92
|
+
Clitopic::Topics.topics.each do |topic_name, topic|
|
93
|
+
yaml = yaml.gsub("#{topic_name}$comment:", topic_comment(topic))
|
94
|
+
if topic.commands.size > 0
|
95
|
+
topic.commands.each do |c, cmd|
|
96
|
+
yaml = yaml.gsub("#{c}$comment:", cmd_comment(cmd))
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
85
102
|
File.open(file, 'wb') do |file|
|
86
|
-
file.write(
|
103
|
+
file.write(yaml)
|
87
104
|
end
|
88
105
|
return opts
|
89
106
|
end
|
90
107
|
|
108
|
+
def topic_comment(topic)
|
109
|
+
"\n # Topic: #{topic.name}\n" +
|
110
|
+
" # #{topic.description.gsub("\n", "\n # ")}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def cmd_comment(cmd)
|
114
|
+
"\n # #{cmd.fullname}\n" +
|
115
|
+
" # #{cmd.short_description}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def opt_comment(opt)
|
119
|
+
"# "
|
120
|
+
end
|
91
121
|
def call
|
92
122
|
puts @options
|
93
123
|
if @arguments.size == 0
|
@@ -8,18 +8,6 @@ module Clitopic
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module Command
|
11
|
-
class Help2 < Clitopic::Command::Base
|
12
|
-
register name: 'help2',
|
13
|
-
description: "Display helps",
|
14
|
-
banner: "Display helps",
|
15
|
-
topic: "help"
|
16
|
-
|
17
|
-
option :all, "--all", "Display all topics with all commands"
|
18
|
-
option :topics, "--topics", "Display all availables topics"
|
19
|
-
option :topic, "--topic=TOPIC", "Display availables commands for the TOPIC"
|
20
|
-
option :with_hidden, "--with-hidden", "Include hidden commands/topics"
|
21
|
-
end
|
22
|
-
|
23
11
|
class Help < Clitopic::Command::Base
|
24
12
|
register name: 'index',
|
25
13
|
banner: "Usage: #{Clitopic.name} help [COMMAND]",
|
data/lib/clitopic/helpers.rb
CHANGED
@@ -30,14 +30,23 @@ module Clitopic
|
|
30
30
|
parser.base.long.delete('version')
|
31
31
|
process_options(parser, self.cmd_options)
|
32
32
|
|
33
|
-
if !self.topic.nil?
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if !self.topic.nil?
|
34
|
+
self.inherited_options.each do |cmd|
|
35
|
+
cmd = self.topic.commands[cmd.to_s]
|
36
|
+
parser.separator ""
|
37
|
+
parser.separator "'#{cmd.fullname}' inherited options"
|
38
|
+
process_options(parser, cmd.cmd_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
if self.topic.topic_options.size > 0
|
42
|
+
parser.separator ""
|
43
|
+
parser.separator "Topic options"
|
44
|
+
process_options(parser, self.topic.topic_options)
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
parser.separator ""
|
40
|
-
parser.separator "Common options
|
49
|
+
parser.separator "Common options"
|
41
50
|
process_options(parser, Clitopic::Commands.global_options)
|
42
51
|
|
43
52
|
# No argument, shows at tail. This will print an options summary.
|
data/lib/clitopic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-topic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Legrand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|