cli-topic 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8003d6632558c53150f15cf2a82014647761331b
4
- data.tar.gz: a677aa796f1db1f45c00b62881994cddd962a90c
3
+ metadata.gz: 69133ceab5e2dd9f9b2c2951f950ce3e747e25b6
4
+ data.tar.gz: b4b3dd0561e6a1b903b2d1c14a1420353a14bba3
5
5
  SHA512:
6
- metadata.gz: 38947da78454ed0682444d86365dfd6239da094ecccc16badd3381aef6919b54eb8f7f6978d395f0a0dd9d124c16538b0519152951f53b288d319e8ab7e47f9a
7
- data.tar.gz: 2bfbbf15f4e7126d190e958eaa8379c30fa42ff0fa79d80dffb4bb8013bd290bd630a0ee714e8324094a7e167929a9ae6f9482ff7bb14fb33035cb83d02ce643
6
+ metadata.gz: 99223e53b380536a589bb9f3752a43db56f3ce4ec46d070afaa1729438713a85ac897a83400e35cc813ee8046b0b4d8c23e74dc74ba38c4765d4b40cf07d77db
7
+ data.tar.gz: 83e6817b3568220fb3da79972aee428f0c689a0009c1cc2019405d6ed3d117162b0d09ce12d664c57b037418b5f6923181aa863607e378f6bbb77ebb37c6db40
@@ -71,10 +71,10 @@ module Clitopic
71
71
  opts.each do |name, value|
72
72
  name = name.to_s.to_sym
73
73
  if !value.nil?
74
- if options[name].nil?
75
- options[name] = value
76
- elsif options[name].is_a?(Array)
74
+ if options[name].is_a?(Array)
77
75
  options[name] += value
76
+ else
77
+ options[name] = value
78
78
  end
79
79
  end
80
80
  end
@@ -106,20 +106,20 @@ module Clitopic
106
106
  cmd_defaults = defaults["commands"][self.name]
107
107
  end
108
108
  else
109
- if defaults.has_key?(self.topic.name)
110
- cmd_defaults = defaults[self.topic.name][self.name]
111
- topic_opts = defaults[self.topic.name]['topic_options']
109
+ if defaults.has_key?("topics") && defaults["topics"].has_key?(self.topic.name)
110
+ cmd_defaults = defaults['topics'][self.topic.name][self.name]
111
+ topic_opts = defaults['topics'][self.topic.name]['topic_options']
112
112
  end
113
113
  end
114
114
 
115
+ load_options(topic_opts)
116
+
115
117
  if cmd_defaults.nil?
116
118
  puts "no defaults"
117
119
  return
118
120
  end
119
121
 
120
- load_options(topic_opts)
121
122
  load_options(cmd_defaults["options"])
122
-
123
123
  if cmd_defaults["args"] && !arguments
124
124
  @arguments += Array(cmd_defaults["args"])
125
125
  end
@@ -42,6 +42,11 @@ module Clitopic
42
42
  end
43
43
  end
44
44
 
45
+ def deep_merge(h1, h2)
46
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
47
+ h1.merge(h2, &merger)
48
+ end
49
+
45
50
  def dump_options(file, merge=true, force=false)
46
51
  opts = {"common_options" => {}}
47
52
  opts["common_options"] = {} if Clitopic::Commands.global_options.size > 0
@@ -52,16 +57,17 @@ module Clitopic
52
57
  Clitopic::Commands.global_commands.each do |c, cmd|
53
58
  cmd_opts(cmd, opts["commands"])
54
59
  end
60
+ opts['topics'] = {}
55
61
  Clitopic::Topics.topics.each do |topic_name, topic|
56
62
  if (!topic.hidden || options[:hidden])
57
- opts[topic_name] = {}
58
- opts[topic_name]["topic_options"] = {} if topic.topic_options.size > 0
63
+ opts['topics'][topic_name] = {}
64
+ opts['topics'][topic_name]["topic_options"] = {} if topic.topic_options.size > 0
59
65
  topic.topic_options.each do |opt|
60
- opts[topic_name]["topic_options"][opt[:name].to_s] = opt[:default]
66
+ opts['topics'][topic_name]["topic_options"][opt[:name].to_s] = opt[:default]
61
67
  end
62
68
  if topic.commands.size > 0
63
69
  topic.commands.each do |c, cmd|
64
- cmd_opts(cmd, opts[topic_name])
70
+ cmd_opts(cmd, opts['topics'][topic_name])
65
71
  end
66
72
  end
67
73
  end
@@ -72,7 +78,7 @@ module Clitopic
72
78
  raise ArgumentError.new("File #{file} exists, use --merge or --force")
73
79
  end
74
80
  if merge && !force
75
- opts = opts.merge(YAML.load_file(file))
81
+ opts = deep_merge(opts, YAML.load_file(file))
76
82
  end
77
83
  end
78
84
  puts "write: #{file}"
@@ -111,26 +111,6 @@ module Clitopic
111
111
  end
112
112
  end
113
113
 
114
- def display_topic(topic_name, with_commands=false, with_header=false)
115
- if with_commands
116
- longest = longest_cmd
117
- else
118
- longest = longest_topic
119
- end
120
- topic = Topics[topic_name]
121
- header(topic) if with_header
122
-
123
- if topic.hidden == false || options[:with_hidden] == true
124
- puts ("%-#{longest + 3}s # %s" % [ "#{topic_name}", "#{topic.short_description}" ]).indent(2)
125
- if with_commands
126
- topic.commands.each do |cmd_name, cmd|
127
- puts (" %-#{longest}s # %s" % [ "#{cmd.fullname}", "#{cmd.short_description}"]).indent(2)
128
- end
129
- puts ""
130
- end
131
- end
132
- end
133
-
134
114
  def display_topics(with_commands=false)
135
115
  puts "Additional topics:\n\n"
136
116
  Clitopic::Topics.topics.each do |topic_name, topic|
@@ -97,10 +97,10 @@ module Clitopic
97
97
  "See `help` for a list of available commands."
98
98
  ].compact.join("\n\n"))
99
99
  end
100
- prepare_run(@current_cmd, arguments)
101
100
  if @current_cmd.options[:load_defaults] == true || Clitopic.load_defaults?
102
101
  @current_cmd.load_defaults
103
102
  end
103
+ prepare_run(@current_cmd, arguments)
104
104
  @current_cmd.call
105
105
  end
106
106
 
@@ -74,12 +74,12 @@ module Clitopic
74
74
  def confirm_command(app_to_confirm = app, message=nil)
75
75
  if confirmed_app = Clitopic::Commands.current_options[:confirm]
76
76
  unless confirmed_app == app_to_confirm
77
- raise(Clitopic::Command::CommandFailed, "Confirmed app #{confirmed_app} did not match the selected app #{app_to_confirm}.")
77
+ raise(Clitopic::Commands::CommandFailed, "Confirmed app #{confirmed_app} did not match the selected app #{app_to_confirm}.")
78
78
  end
79
79
  return true
80
80
  else
81
81
  display
82
- message ||= "WARNING: Destructive Action\nThis command will affect the app: #{app_to_confirm}"
82
+ message ||= "WARNING: Destructive Action\n"
83
83
  message << "\nTo proceed, type \"#{app_to_confirm}\" or re-run this command with --confirm #{app_to_confirm}"
84
84
  output_with_bang(message)
85
85
  display
@@ -109,28 +109,6 @@ module Clitopic
109
109
  Clitopic::Command.run(command, args)
110
110
  end
111
111
 
112
- def retry_on_exception(*exceptions)
113
- retry_count = 0
114
- begin
115
- yield
116
- rescue *exceptions => ex
117
- raise ex if retry_count >= 3
118
- sleep 3
119
- retry_count += 1
120
- retry
121
- end
122
- end
123
-
124
- def has_git?
125
- %x{ git --version }
126
- $?.success?
127
- end
128
-
129
- def git(args)
130
- return "" unless has_git?
131
- flattened_args = [args].flatten.compact.join(" ")
132
- %x{ git #{flattened_args} 2>&1 }.strip
133
- end
134
112
 
135
113
  def time_ago(since)
136
114
  if since.is_a?(String)
@@ -258,7 +236,7 @@ module Clitopic
258
236
  end
259
237
 
260
238
  def fail(message)
261
- raise Clitopic::Command::CommandFailed, message
239
+ raise Clitopic::Commands::CommandFailed, message
262
240
  end
263
241
 
264
242
  ## DISPLAY HELPERS
@@ -413,8 +391,8 @@ module Clitopic
413
391
  def format_error(error, message='Clitopic client internal error.')
414
392
  formatted_error = []
415
393
  formatted_error << " ! #{message}"
416
- formatted_error << ' ! Search for help at: https://help.clitopic.com"'
417
- formatted_error << ' ! Or report a bug at: https://github.com/ant31/clitopic/issues/new'
394
+ formatted_error << " ! Search for help at: #{Clitopic.help_page || "https://github.com/ant31/cli-topic/wiki"}"
395
+ formatted_error << " ! Or report a bug at: #{Clitopic.issue_report || "https://github.com/ant31/cli-topic/issues/new"} "
418
396
  formatted_error << ''
419
397
 
420
398
  command = ARGV.map do |arg|
@@ -1,3 +1,3 @@
1
1
  module Clitopic
2
- VERSION = '0.9.6'
2
+ VERSION = '0.9.7'
3
3
  end
data/lib/clitopic.rb CHANGED
@@ -3,7 +3,7 @@ require 'clitopic/parsers'
3
3
 
4
4
  module Clitopic
5
5
  class << self
6
- attr_accessor :debug, :commands_dir, :version, :default_files, :load_defaults, :name
6
+ attr_accessor :debug, :commands_dir, :version, :default_files, :load_defaults, :name, :help_page, :issue_report
7
7
  def name
8
8
  @name ||= 'clito'
9
9
  end
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,9 @@ require "codeclimate-test-reporter"
19
19
  CodeClimate::TestReporter.start
20
20
  SimpleCov.start do
21
21
  add_filter 'spec/'
22
+ add_filter 'lib/clitopic/helpers.rb'
22
23
  add_group 'lib', 'lib'
24
+ add_group 'commands', 'lib/clitopic/command'
23
25
  end
24
26
 
25
27
  require 'clitopic'
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.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Legrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec