bogo-cli 0.1.24 → 0.1.26

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: 613e4cf3d1e1517fc29f3bc1810d440a854c7836
4
- data.tar.gz: 6d1824a5e2fafac57c6a26b6946b63987b35eeca
3
+ metadata.gz: 733cb704c0dbee10eeecbee3b8ef8e82c240f37a
4
+ data.tar.gz: 7e8277e7ce4ad6d6db726580e9514ff4b2ba5921
5
5
  SHA512:
6
- metadata.gz: 9558b7ef49c1756bf564247176f274361dd2d0be07be1406fbb431d12f2b7ba3b4f5ac909ab6ab8f48bff39d09538f3bc218a0c98961f2ede3002f6e7a0798db
7
- data.tar.gz: 28a7958b8184a601f8302e53b79fadbf50c728bc0bb3ab280c49509522fdec72854da13e2797fb1f2cd3da3718599a37baf8201471a246467a99463ffe027f79
6
+ metadata.gz: bef3ad2a370a30934ee4ceb7ab598cd09b3395cfad5dc55b635ea1d33472520901d5569faf21b78e83334cfe979588ae284a6cc752716df16e60622b7f66a4bc
7
+ data.tar.gz: ae66cbe20d18884bf2763923147bc9d74b2134b72b4be37968b16817b80b0a810bfc50516a3c5d03768eaec1724626533552634de893462e63ada7a9d14594ea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.1.26
2
+ * Properly merge user provided options on top of defaults
3
+ * Add helper method for determining if option is set as default
4
+
1
5
  ## v0.1.24
2
6
  * [fix] Remove configuration items with `nil` values
3
7
 
@@ -11,6 +11,8 @@ module Bogo
11
11
 
12
12
  # @return [Hash] options
13
13
  attr_reader :options
14
+ # @return [Hash] default options
15
+ attr_reader :defaults
14
16
  # @return [Array] cli arguments
15
17
  attr_reader :arguments
16
18
  # @return [Ui]
@@ -20,10 +22,15 @@ module Bogo
20
22
  #
21
23
  # @return [self]
22
24
  def initialize(cli_opts, args)
23
- @options = cli_opts.to_hash.to_smash(:snake)
24
- [@options, *@options.values].compact.each do |hsh|
25
- next unless hsh.is_a?(Hash)
26
- hsh.delete_if{|k,v| v.nil?}
25
+ if(cli_opts.is_a?(Slop))
26
+ process_cli_options(cli_opts)
27
+ else
28
+ @defaults = Smash.new
29
+ @options = cli_opts.to_hash.to_smash(:snake)
30
+ [@options, *@options.values].compact.each do |hsh|
31
+ next unless hsh.is_a?(Hash)
32
+ hsh.delete_if{|k,v| v.nil?}
33
+ end
27
34
  end
28
35
  @arguments = args
29
36
  ui_args = Smash.new(
@@ -84,12 +91,21 @@ module Bogo
84
91
  end
85
92
  config_inst = config_class.new(path) if path
86
93
  end
87
- new_opts = config_class.new(options)
88
- @options = new_opts.to_smash
89
94
  if(config_inst)
90
- merge_opts = Smash[options.to_smash.map{|k,v| [k,v] unless v.nil?}.compact]
91
- merge_opts.delete(:config)
92
- @options = config_inst.to_smash.deep_merge(merge_opts)
95
+ options.delete(:config)
96
+ @options = config_class.new(
97
+ defaults.to_smash.deep_merge(
98
+ config_inst.to_smash.deep_merge(
99
+ options.to_smash
100
+ )
101
+ )
102
+ ).to_smash
103
+ else
104
+ @options = config_class.new(
105
+ default.to_smash.deep_merge(
106
+ options.to_smash
107
+ )
108
+ ).to_smash
93
109
  end
94
110
  options
95
111
  end
@@ -129,6 +145,30 @@ module Bogo
129
145
  true
130
146
  end
131
147
 
148
+ # Process the given CLI options and isolate default values from
149
+ # user provided values
150
+ #
151
+ # @param cli_opts [Slop]
152
+ # @return [NilClass]
153
+ def process_cli_options(cli_opts)
154
+ unless(cli_opts.is_a?(Slop))
155
+ raise TypeError.new "Expecting type `Slop` but received type `#{cli_opts.class}`"
156
+ end
157
+ @options = Smash.new
158
+ @defaults = Smash.new
159
+ cli_opts.each do |cli_opt|
160
+ unless(cli_opt.value.nil?)
161
+ opt_key = Bogo::Utility.snake(cli_opt.key)
162
+ if(cli_opt.default?)
163
+ @defaults[opt_key] = cli_opt.value
164
+ else
165
+ @options[opt_key] = cli_opt.value
166
+ end
167
+ end
168
+ end
169
+ nil
170
+ end
171
+
132
172
  end
133
173
 
134
174
  end
@@ -1,6 +1,5 @@
1
1
  Signal.trap('INT'){ exit -1 }
2
2
 
3
- require 'slop'
4
3
  require 'bogo-cli'
5
4
 
6
5
  class Slop
@@ -11,6 +10,11 @@ class Slop
11
10
  end
12
11
  alias_method :slop_run, :run
13
12
  alias_method :run, :bogo_cli_run
13
+ class Option
14
+ def default?
15
+ @value.nil?
16
+ end
17
+ end
14
18
  end
15
19
 
16
20
  module Bogo
@@ -1,6 +1,6 @@
1
1
  module Bogo
2
2
  module Cli
3
3
  # Current library version
4
- VERSION = Gem::Version.new('0.1.24')
4
+ VERSION = Gem::Version.new('0.1.26')
5
5
  end
6
6
  end
data/lib/bogo-cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'bogo'
2
+ require 'slop'
2
3
  require 'bogo-config'
3
4
 
4
5
  module Bogo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bogo-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-30 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bogo