rake-commander 0.2.3 → 0.2.4
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 +4 -4
 - data/CHANGELOG.md +8 -4
 - data/lib/rake-commander/options.rb +16 -4
 - data/lib/rake-commander/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e676c7895883ca91c58c1ef5a025a4a8f52795ed12ac79e2e53f304b59e5a9ee
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 871c881ac31b06e1cf4a13bab7846d063bfee83bfcca4b332eeeb345f04c3051
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 78d4f8199e7e220d26e48346fd0cd23aec273c739ee8bcd949ed12cf147191ec988f056d6ef273f5dc186e64bb71a2bc7eb33dbcbc2525f2d20278dac3ce1df2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 31a2dca9846b7521b43ca14d79a562f57a30fafad01af42e3a0886e4aceb3b4d43d71f8b6133f08ca538cbf9e6d5210ed82447dbfb20f70ea8ab315797dedae7
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -32,20 +32,24 @@ All notable changes to this project will be documented in this file. 
     | 
|
| 
       32 
32 
     | 
    
         
             
              - Option to globally enable/disable the 2nd patch?
         
     | 
| 
       33 
33 
     | 
    
         
             
                * That would make this gem completely useless.
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
            ## [0.2. 
     | 
| 
      
 35 
     | 
    
         
            +
            ## [0.2.5] - 2023-04-xx
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
37 
     | 
    
         
             
            ### Added
         
     | 
| 
       38 
38 
     | 
    
         
             
            ### Fixed
         
     | 
| 
       39 
39 
     | 
    
         
             
            ### Changed
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
            ## [0.2.4] - 2023-04-30
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            ### Added
         
     | 
| 
      
 44 
     | 
    
         
            +
              - `RakeCommander::Options`
         
     | 
| 
      
 45 
     | 
    
         
            +
                - `::option_get` retrieves an option by name or short, may it exist.
         
     | 
| 
      
 46 
     | 
    
         
            +
                - `::option?` to check if an opion exists.
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       41 
48 
     | 
    
         
             
            ## [0.2.3] - 2023-04-29
         
     | 
| 
       42 
49 
     | 
    
         | 
| 
       43 
50 
     | 
    
         
             
            ### Added
         
     | 
| 
       44 
51 
     | 
    
         
             
              - Include Symbol option names in the parsed option results.
         
     | 
| 
       45 
52 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
            ### Fixed
         
     | 
| 
       47 
     | 
    
         
            -
            ### Changed
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
53 
     | 
    
         
             
            ## [0.2.2] - 2023-04-29
         
     | 
| 
       50 
54 
     | 
    
         | 
| 
       51 
55 
     | 
    
         
             
            ### Fixed
         
     | 
| 
         @@ -94,6 +94,18 @@ class RakeCommander 
     | 
|
| 
       94 
94 
     | 
    
         
             
                    options_hash.values.uniq
         
     | 
| 
       95 
95 
     | 
    
         
             
                  end
         
     | 
| 
       96 
96 
     | 
    
         | 
| 
      
 97 
     | 
    
         
            +
                  # @param sym [Symbol] the `name` or `short` of the option.
         
     | 
| 
      
 98 
     | 
    
         
            +
                  # @return [RakeCommander::Option, NilClass] retrieves the option.
         
     | 
| 
      
 99 
     | 
    
         
            +
                  def option_get(sym)
         
     | 
| 
      
 100 
     | 
    
         
            +
                    options_hash[sym.to_sym]
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  # @param sym [Symbol] the `name` or `short` of the option.
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # @return [Boolean] whether an option has been declared.
         
     | 
| 
      
 105 
     | 
    
         
            +
                  def option?(sym)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    options_hash.key?(sym.to_sym)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
       97 
109 
     | 
    
         
             
                  # @return [Boolean] are there options defined?
         
     | 
| 
       98 
110 
     | 
    
         
             
                  def options?
         
     | 
| 
       99 
111 
     | 
    
         
             
                    !options.empty?
         
     | 
| 
         @@ -149,7 +161,7 @@ class RakeCommander 
     | 
|
| 
       149 
161 
     | 
    
         
             
                  def implicit_shorts
         
     | 
| 
       150 
162 
     | 
    
         
             
                    options.each_with_object({}) do |opt, implicit|
         
     | 
| 
       151 
163 
     | 
    
         
             
                      short = opt.short_implicit
         
     | 
| 
       152 
     | 
    
         
            -
                      implicit[short] = opt unless  
     | 
| 
      
 164 
     | 
    
         
            +
                      implicit[short] = opt unless option?(short)
         
     | 
| 
       153 
165 
     | 
    
         
             
                    end
         
     | 
| 
       154 
166 
     | 
    
         
             
                  end
         
     | 
| 
       155 
167 
     | 
    
         | 
| 
         @@ -159,7 +171,7 @@ class RakeCommander 
     | 
|
| 
       159 
171 
     | 
    
         
             
                  # @note `OptionParser` already has `-h --help` as a native option.
         
     | 
| 
       160 
172 
     | 
    
         
             
                  # @param opts [OptionParser] where the help will be added.
         
     | 
| 
       161 
173 
     | 
    
         
             
                  def option_help(opts)
         
     | 
| 
       162 
     | 
    
         
            -
                    return false if  
     | 
| 
      
 174 
     | 
    
         
            +
                    return false if option?(:help) || option?(:h)
         
     | 
| 
       163 
175 
     | 
    
         
             
                    option(:h, :help, 'Prints this help') do
         
     | 
| 
       164 
176 
     | 
    
         
             
                      puts opts
         
     | 
| 
       165 
177 
     | 
    
         
             
                      exit(0)
         
     | 
| 
         @@ -191,12 +203,12 @@ class RakeCommander 
     | 
|
| 
       191 
203 
     | 
    
         
             
                  # @return [RakeCommander::Option, NilClass] the option that was added, `nil` is returned otherwise.
         
     | 
| 
       192 
204 
     | 
    
         
             
                  def add_to_options(opt, override: true)
         
     | 
| 
       193 
205 
     | 
    
         
             
                    name_ref = respond_to?(:name)? " (#{name})" : ''
         
     | 
| 
       194 
     | 
    
         
            -
                    if sprev =  
     | 
| 
      
 206 
     | 
    
         
            +
                    if sprev = option_get(opt.short)
         
     | 
| 
       195 
207 
     | 
    
         
             
                      return nil unless override
         
     | 
| 
       196 
208 
     | 
    
         
             
                      puts "Warning#{name_ref}: Overriding option '#{sprev.name}' with short '#{sprev.short}' ('#{opt.name}')"
         
     | 
| 
       197 
209 
     | 
    
         
             
                      delete_from_options(sprev)
         
     | 
| 
       198 
210 
     | 
    
         
             
                    end
         
     | 
| 
       199 
     | 
    
         
            -
                    if nprev =  
     | 
| 
      
 211 
     | 
    
         
            +
                    if nprev = option_get(opt.name)
         
     | 
| 
       200 
212 
     | 
    
         
             
                      return nil unless override
         
     | 
| 
       201 
213 
     | 
    
         
             
                      puts "Warning#{name_ref}: Overriding option '#{nprev.short}' with name '#{nprev.name}' ('#{opt.short}')"
         
     | 
| 
       202 
214 
     | 
    
         
             
                      delete_from_options(nprev)
         
     |