cli-topic 0.9.11 → 0.9.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a26b2f2dd89ac0caefe2857dca7572a5e5fdcc27
4
- data.tar.gz: b6d109a43943d7bb9df655ca9f5ec0904523b82f
3
+ metadata.gz: e72fc927c07de8676cfbe9825039668fb13e8f2b
4
+ data.tar.gz: a2e3ca0c238ed29f0bdedd98b4df5307f03f26e0
5
5
  SHA512:
6
- metadata.gz: 3c11a6283867ee89d3f6568f9363263e0e20a5c457d2cbf3ddd57ec3d4530b566b12322df28ef896cfdd0b9e14c7fccae977af52b02b1b66688b083883263bbc
7
- data.tar.gz: d18c8fab5ed577a26644e581c2551c09a5cc11972ba1193318923dd31b9c0e9762c609102ace22e938b17605e75d48f71488d7db0c00b3ad343860871212d952
6
+ metadata.gz: 9224fb4818253124250723f60f6092724f90f531e8fd66c58e55a7e8717f1dabc022bcda5c7bc086f203a5694e6d10eeec3241227c2ea2da26c1a696174bfa86
7
+ data.tar.gz: b657642f2745be86b60c15c2c23354e70289b7d934c29ea405f74996db185e6f7c504c2ef2c8473f452bcd658cc9efad52ba0330d7f73e9b37c8d9e3536927a6
@@ -23,14 +23,14 @@ module Clitopic
23
23
  end
24
24
 
25
25
  class DefaultsFile < Clitopic::Command::Base
26
- register name: 'defaults_file',
26
+ register name: 'create-defaults',
27
27
  description: "create default file",
28
- hidden: true,
28
+ hidden: false,
29
29
  topic: 'clitopic'
30
30
 
31
31
  option :merge, "--[no-]merge", "Merge options with current file", default: true
32
32
  option :force, "-f", "--force", "Overwrite file", default: false
33
-
33
+ option :topics, "-t", "--topics TOPICS", Array, "create file for TOPICS list only"
34
34
 
35
35
  class << self
36
36
  def cmd_opts(cmd, opts)
@@ -40,7 +40,8 @@ module Clitopic
40
40
  opts = opts[cmd_comment]
41
41
  opts[cmd.name] = {"options" => {}, "args" => []}
42
42
  cmd.cmd_options.each do |opt|
43
- opts[cmd.name]["options"][opt[:name].to_s] = opt[:default]
43
+ opts[cmd.name]["options"]["#{opt[:name].to_s}$comment"] = {}
44
+ opts[cmd.name]["options"]["#{opt[:name].to_s}$comment"][opt[:name].to_s] = opt[:default]
44
45
  end
45
46
  end
46
47
  end
@@ -62,13 +63,17 @@ module Clitopic
62
63
  end
63
64
  opts['topics'] = {}
64
65
  Clitopic::Topics.topics.each do |topic_name, topic|
66
+ if @options[:topics] && !@options[:topics].index(topic_name.to_s)
67
+ next
68
+ end
69
+
65
70
  if (!topic.hidden || options[:hidden])
66
71
  topic_comment = "#{topic_name}$comment"
67
72
  opts['topics'][topic_comment] = {}
68
73
  opts['topics'][topic_comment][topic_name] = {}
69
- opts['topics'][topic_comment][topic_name]["topic_options"] = {} if topic.topic_options.size > 0
74
+ opts['topics'][topic_comment][topic_name]["topic_options$comment"] = {"topic_options" => {}} if topic.topic_options.size > 0
70
75
  topic.topic_options.each do |opt|
71
- opts['topics'][topic_comment][topic_name]["topic_options"][opt[:name].to_s] = opt[:default]
76
+ opts['topics'][topic_comment][topic_name]["topic_options$comment"]["topic_options"][opt[:name].to_s] = opt[:default]
72
77
  end
73
78
  if topic.commands.size > 0
74
79
  topic.commands.each do |c, cmd|
@@ -88,17 +93,16 @@ module Clitopic
88
93
  end
89
94
  puts "write: #{file}"
90
95
  yaml = opts.to_yaml
91
-
96
+ yaml = yaml.gsub("topic_options$comment:", " # common-topic options")
92
97
  Clitopic::Topics.topics.each do |topic_name, topic|
93
- yaml = yaml.gsub("#{topic_name}$comment:", topic_comment(topic))
98
+ yaml = yaml.gsub(/(\s+)#{topic_name}\$comment:/, '\1' + topic_comment(topic))
94
99
  if topic.commands.size > 0
95
100
  topic.commands.each do |c, cmd|
96
- yaml = yaml.gsub("#{c}$comment:", cmd_comment(cmd))
101
+ yaml = yaml.gsub(/(\s+)#{c}\$comment:/, '\1' + cmd_comment(cmd))
102
+ yaml = opt_comment(cmd, yaml)
97
103
  end
98
104
  end
99
-
100
105
  end
101
-
102
106
  File.open(file, 'wb') do |file|
103
107
  file.write(yaml)
104
108
  end
@@ -115,13 +119,18 @@ module Clitopic
115
119
  " # #{cmd.short_description}"
116
120
  end
117
121
 
118
- def opt_comment(opt)
119
- "# "
122
+ def opt_comment(cmd, yaml)
123
+ if cmd.cmd_options.size > 0 && (!cmd.hidden || options[:hidden])
124
+ cmd.cmd_options.each do |opt|
125
+ yaml = yaml.gsub(/(\s+)#{opt[:name].to_s}\$comment:/, '\1' + "# #{opt[:args].last}")
126
+ end
127
+ end
128
+ return yaml
120
129
  end
130
+
121
131
  def call
122
- puts @options
123
132
  if @arguments.size == 0
124
- file = Clitopic::Helpers.find_default_file
133
+ file = Clitopic::Helpers.find_default_file || Clitopic.default_files.first
125
134
  if file.nil?
126
135
  raise ArgumentError.new("Missing file")
127
136
  end
@@ -1,3 +1,3 @@
1
1
  module Clitopic
2
- VERSION = '0.9.11'
2
+ VERSION = '0.9.12'
3
3
  end
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.11
4
+ version: 0.9.12
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-08 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec