bini 0.5.5 → 0.6.0
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.
- data/.gitignore +1 -0
 - data/.rspec +1 -1
 - data/.yardopts +1 -0
 - data/CHANGELOG.md +8 -0
 - data/Gemfile +2 -0
 - data/Guardfile +5 -4
 - data/README.md +2 -5
 - data/lib/bini.rb +20 -43
 - data/lib/bini/config.rb +2 -3
 - data/lib/bini/filemagic.rb +5 -0
 - data/lib/bini/mixins.rb +2 -0
 - data/lib/bini/optparser.rb +18 -14
 - data/lib/bini/prompts.rb +0 -3
 - data/lib/bini/sash.rb +1 -3
 - data/lib/bini/version.rb +2 -1
 - data/spec/{config_spec.rb → lib/bini/config_spec.rb} +3 -3
 - data/spec/{filemagic_spec.rb → lib/bini/filemagic_spec.rb} +4 -0
 - data/spec/{mixins_spec.rb → lib/bini/mixins_spec.rb} +0 -0
 - data/spec/{optparser_spec.rb → lib/bini/optparser_spec.rb} +6 -2
 - data/spec/{sash_spec.rb → lib/bini/sash_spec.rb} +0 -0
 - data/spec/lib/bini_spec.rb +50 -0
 - data/spec/spec_helper.rb +5 -0
 - metadata +16 -20
 - data/spec/bini_spec.rb +0 -92
 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.rspec
    CHANGED
    
    | 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --color
         
     | 
| 
       2 
     | 
    
         
            -
            --format  
     | 
| 
      
 2 
     | 
    
         
            +
            --format documentation
         
     | 
    
        data/.yardopts
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --no-private - LICENSE.txt CHANGELOG.md
         
     | 
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # 0.6.0
         
     | 
| 
      
 2 
     | 
    
         
            +
            * renamed Bini.config to Bini::Config
         
     | 
| 
      
 3 
     | 
    
         
            +
            * 100% test coverage.
         
     | 
| 
      
 4 
     | 
    
         
            +
            * Documentation push.
         
     | 
| 
      
 5 
     | 
    
         
            +
            * Dropped the daemonize code, will implement again later if I decide I need it.
         
     | 
| 
      
 6 
     | 
    
         
            +
            * Dropped kruft like Bini#get_var
         
     | 
| 
      
 7 
     | 
    
         
            +
            * Bini.version works as intended, providing a settable version to use in a given app.
         
     | 
| 
      
 8 
     | 
    
         
            +
            * Options.parse! now takes an ARGV or falls back if nothing is provided.
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -15,9 +15,11 @@ group :development do 
     | 
|
| 
       15 
15 
     | 
    
         
             
            	gem 'rb-inotify', :require => false
         
     | 
| 
       16 
16 
     | 
    
         
             
              gem 'rb-fsevent', :require => false
         
     | 
| 
       17 
17 
     | 
    
         
             
              gem 'rb-fchange', :require => false
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem 'redcarpet',  :require => false
         
     | 
| 
       18 
19 
     | 
    
         
             
            end
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
            group :test do
         
     | 
| 
       21 
22 
     | 
    
         
             
            	gem "rspec"
         
     | 
| 
       22 
23 
     | 
    
         
             
            	gem "rake"
         
     | 
| 
      
 24 
     | 
    
         
            +
            	gem 'simplecov'
         
     | 
| 
       23 
25 
     | 
    
         
             
            end
         
     | 
    
        data/Guardfile
    CHANGED
    
    | 
         @@ -12,7 +12,8 @@ guard :rspec do 
     | 
|
| 
       12 
12 
     | 
    
         
             
              watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
         
     | 
| 
       13 
13 
     | 
    
         
             
              watch('spec/spec_helper.rb')      { "spec" }
         
     | 
| 
       14 
14 
     | 
    
         
             
            end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            group :docs do
         
     | 
| 
      
 16 
     | 
    
         
            +
              guard :yard do
         
     | 
| 
      
 17 
     | 
    
         
            +
                watch(%r{^lib/(.+)\.rb$})
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            A toolbox to help me rapidly build/deploy a cli.  Filled with assumptions about how I think a CLI should behave.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Build Status
         
     | 
| 
       6 
6 
     | 
    
         
             
            <table border="0">
         
     | 
| 
       7 
7 
     | 
    
         
             
              <tr>
         
     | 
| 
       8 
8 
     | 
    
         
             
                <td>master</td>
         
     | 
| 
         @@ -50,10 +50,6 @@ Generated documentation is available via ```yard```. 
     | 
|
| 
       50 
50 
     | 
    
         | 
| 
       51 
51 
     | 
    
         
             
            Examples and wiki coming if they are ever needed.
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
            ## Testing
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
            In theory, testing is complete, in practice it's a work in progress.
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
53 
     | 
    
         
             
            ## Design philosophy
         
     | 
| 
       58 
54 
     | 
    
         | 
| 
       59 
55 
     | 
    
         
             
            If such a thing can be said.
         
     | 
| 
         @@ -69,3 +65,4 @@ If such a thing can be said. 
     | 
|
| 
       69 
65 
     | 
    
         
             
            I don't have rules here, more guidelines.
         
     | 
| 
       70 
66 
     | 
    
         | 
| 
       71 
67 
     | 
    
         
             
            * Try to make the branch name clear, words like feature/issue/bug help.
         
     | 
| 
      
 68 
     | 
    
         
            +
            * Tests.
         
     | 
    
        data/lib/bini.rb
    CHANGED
    
    | 
         @@ -4,9 +4,24 @@ require "bini/sash" 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require "bini/version"
         
     | 
| 
       5 
5 
     | 
    
         
             
            require "bini/filemagic"
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
            # A collection of very small helpers that assist me in writing a CLI without
         
     | 
| 
      
 8 
     | 
    
         
            +
            # getting in the way.
         
     | 
| 
      
 9 
     | 
    
         
            +
            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            # Provides some dynamic attributes, they all behave the same and just hook into
         
     | 
| 
      
 11 
     | 
    
         
            +
            # the defaults to provide non-nil results when needed.
         
     | 
| 
      
 12 
     | 
    
         
            +
            #
         
     | 
| 
      
 13 
     | 
    
         
            +
            # @!attribute long_name [rw]
         
     | 
| 
      
 14 
     | 
    
         
            +
            #  @return [String] An application name, useful if your app is named differently then your binary.
         
     | 
| 
      
 15 
     | 
    
         
            +
            # @!attribute cache_dir [rw]
         
     | 
| 
      
 16 
     | 
    
         
            +
            #  @return [String] The directory to store any cache related files.
         
     | 
| 
      
 17 
     | 
    
         
            +
            # @!attribute config_dir [rw]
         
     | 
| 
      
 18 
     | 
    
         
            +
            #  @return [String] The directory to store any config related files.
         
     | 
| 
      
 19 
     | 
    
         
            +
            # @!attribute version [rw]
         
     | 
| 
      
 20 
     | 
    
         
            +
            #  @return [String] The version of the application, not of Bini.
         
     | 
| 
       7 
21 
     | 
    
         
             
            module Bini
         
     | 
| 
       8 
22 
     | 
    
         
             
              extend self
         
     | 
| 
       9 
23 
     | 
    
         | 
| 
      
 24 
     | 
    
         
            +
              # A collection of sane defaults to be provided if the same attr is still nil.
         
     | 
| 
       10 
25 
     | 
    
         
             
              attr_accessor :defaults
         
     | 
| 
       11 
26 
     | 
    
         | 
| 
       12 
27 
     | 
    
         
             
              # I break this out so that I can use long name right away, this allows methods
         
     | 
| 
         @@ -19,51 +34,20 @@ module Bini 
     | 
|
| 
       19 
34 
     | 
    
         | 
| 
       20 
35 
     | 
    
         
             
              # Dynamic attribute's based off the keys.
         
     | 
| 
       21 
36 
     | 
    
         
             
              def keys
         
     | 
| 
       22 
     | 
    
         
            -
                [:long_name, :cache_dir, :config_dir]
         
     | 
| 
      
 37 
     | 
    
         
            +
                keys ||= [:long_name, :cache_dir, :config_dir, :version]
         
     | 
| 
       23 
38 
     | 
    
         
             
              end
         
     | 
| 
       24 
39 
     | 
    
         | 
| 
       25 
40 
     | 
    
         
             
              keys.each do |key|
         
     | 
| 
       26 
41 
     | 
    
         
             
                define_method(key) do
         
     | 
| 
       27 
42 
     | 
    
         
             
                  v = instance_variable_get "@#{key}"
         
     | 
| 
       28 
     | 
    
         
            -
                  return @defaults[key]  
     | 
| 
       29 
     | 
    
         
            -
                  return v
         
     | 
| 
      
 43 
     | 
    
         
            +
                  return !v ? @defaults[key] : v
         
     | 
| 
       30 
44 
     | 
    
         
             
                end
         
     | 
| 
       31 
45 
     | 
    
         
             
                define_method("#{key}=".to_sym) do |dir|
         
     | 
| 
       32 
46 
     | 
    
         
             
                  instance_variable_set "@#{key}", dir
         
     | 
| 
       33 
47 
     | 
    
         
             
                end
         
     | 
| 
       34 
48 
     | 
    
         
             
              end
         
     | 
| 
       35 
49 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
       37 
     | 
    
         
            -
                a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{@name}.*-[dD].*/}.map {|x| x.pid}
         
     | 
| 
       38 
     | 
    
         
            -
                a.delete $$
         
     | 
| 
       39 
     | 
    
         
            -
                return a if a.any?
         
     | 
| 
       40 
     | 
    
         
            -
                nil
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
              def daemonize(*params, &block)
         
     | 
| 
       45 
     | 
    
         
            -
                if params[0] && !params[0][:multiple_pids] && pids
         
     | 
| 
       46 
     | 
    
         
            -
                  puts :info, "#{@name} appears to be running (#{pids}), only one allowed, exiting."
         
     | 
| 
       47 
     | 
    
         
            -
                  exit
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
                puts :info, "Forking to background."
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                Process.daemon
         
     | 
| 
       52 
     | 
    
         
            -
                block.call
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
              def kill_daemon
         
     | 
| 
       56 
     | 
    
         
            -
                if !pids
         
     | 
| 
       57 
     | 
    
         
            -
                  puts :fatal, "No pids found, exiting."
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                pids.each do |p|
         
     | 
| 
       61 
     | 
    
         
            -
                  puts :info, "Killing #{p}"
         
     | 
| 
       62 
     | 
    
         
            -
                  `kill -TERM #{p}`
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
              # Adds a rails style configure method (@benwoody's unknown contribution)
         
     | 
| 
      
 50 
     | 
    
         
            +
              # Adds a rails style configure method.
         
     | 
| 
       67 
51 
     | 
    
         
             
              def configure
         
     | 
| 
       68 
52 
     | 
    
         
             
                yield self
         
     | 
| 
       69 
53 
     | 
    
         
             
                parameters
         
     | 
| 
         @@ -77,16 +61,9 @@ module Bini 
     | 
|
| 
       77 
61 
     | 
    
         
             
              end
         
     | 
| 
       78 
62 
     | 
    
         
             
              alias_method :params, :parameters
         
     | 
| 
       79 
63 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
              # Returns true or false if all parameters are set.
         
     | 
| 
      
 64 
     | 
    
         
            +
              # Returns true or false if all parameters are set to something other than defaults.
         
     | 
| 
       81 
65 
     | 
    
         
             
              def parameters?
         
     | 
| 
       82 
     | 
    
         
            -
                parameters. 
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
              private
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
              # Helper to clean up recursive method in #parameters
         
     | 
| 
       88 
     | 
    
         
            -
              def get_var(var)
         
     | 
| 
       89 
     | 
    
         
            -
                self.instance_variable_get(var)
         
     | 
| 
      
 66 
     | 
    
         
            +
                @defaults.map {|k,v| @defaults[k] != parameters[k]}.all?
         
     | 
| 
       90 
67 
     | 
    
         
             
              end
         
     | 
| 
       91 
68 
     | 
    
         
             
            end
         
     | 
| 
       92 
69 
     | 
    
         | 
    
        data/lib/bini/config.rb
    CHANGED
    
    | 
         @@ -1,9 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Bini
         
     | 
| 
       4 
     | 
    
         
            -
              attr_accessor :config
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
4 
     | 
    
         
             
              extend self
         
     | 
| 
       7 
5 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
      
 6 
     | 
    
         
            +
              # A helper for storing configuration related data in.
         
     | 
| 
      
 7 
     | 
    
         
            +
              Config = Sash.new file:"#{Bini.config_dir}/#{Bini.name}.yaml"
         
     | 
| 
       9 
8 
     | 
    
         
             
            end
         
     | 
    
        data/lib/bini/filemagic.rb
    CHANGED
    
    | 
         @@ -1,7 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Bini
         
     | 
| 
      
 2 
     | 
    
         
            +
              # A collection of helpers related to file management.
         
     | 
| 
       2 
3 
     | 
    
         
             
              module FileMagic
         
     | 
| 
       3 
4 
     | 
    
         
             
                extend self
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
                # Call the system app 'file' to check mimetype.
         
     | 
| 
      
 7 
     | 
    
         
            +
                # @param [String] file name of the file.
         
     | 
| 
      
 8 
     | 
    
         
            +
                # @return [String] of the mimetypes found
         
     | 
| 
      
 9 
     | 
    
         
            +
                # @return [Nil] if nothing worked.
         
     | 
| 
       5 
10 
     | 
    
         
             
                def mime_type(file)
         
     | 
| 
       6 
11 
     | 
    
         
             
                  return `file -bk --mime-type "#{file}"`.chomp! if File.exist? file
         
     | 
| 
       7 
12 
     | 
    
         
             
                  return nil
         
     | 
    
        data/lib/bini/mixins.rb
    CHANGED
    
    
    
        data/lib/bini/optparser.rb
    CHANGED
    
    | 
         @@ -1,6 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module Bini
         
     | 
| 
      
 4 
     | 
    
         
            +
              # An extension of [OptionParser] that behaves like a hash, with saving, loading, and
         
     | 
| 
      
 5 
     | 
    
         
            +
              # mashing in other hashs.
         
     | 
| 
       4 
6 
     | 
    
         
             
              class OptionParser < ::OptionParser
         
     | 
| 
       5 
7 
     | 
    
         
             
                def initialize
         
     | 
| 
       6 
8 
     | 
    
         
             
                  super
         
     | 
| 
         @@ -9,33 +11,33 @@ module Bini 
     | 
|
| 
       9 
11 
     | 
    
         
             
                  on("-V", "--version", "Print version") { |version| @options[:version] = true}
         
     | 
| 
       10 
12 
     | 
    
         
             
                end
         
     | 
| 
       11 
13 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
      
 14 
     | 
    
         
            +
                # Parse out ARGV, includes a catch for returning version, otherwise just calls super.
         
     | 
| 
      
 15 
     | 
    
         
            +
                def parse!(*argv)
         
     | 
| 
       13 
16 
     | 
    
         
             
                  super
         
     | 
| 
       14 
17 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                  if  
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
       19 
     | 
    
         
            -
                      puts "No version supplied."
         
     | 
| 
       20 
     | 
    
         
            -
                    end
         
     | 
| 
       21 
     | 
    
         
            -
                    exit 0
         
     | 
| 
      
 18 
     | 
    
         
            +
                  if Options[:version] && Bini.version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    puts Bini.version
         
     | 
| 
      
 20 
     | 
    
         
            +
                    # don't exit if RSpec is around, we are in a testing environment.
         
     | 
| 
      
 21 
     | 
    
         
            +
                    exit 0 if !Object.constants.include? :RSpec
         
     | 
| 
       22 
22 
     | 
    
         
             
                  end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                  mash Bini.config if Bini.config
         
     | 
| 
       25 
23 
     | 
    
         
             
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
24 
     | 
    
         
             
                # These are the hash like bits.
         
     | 
| 
       28 
25 
     | 
    
         | 
| 
      
 26 
     | 
    
         
            +
                # Clear the contents of the builtin Hash.
         
     | 
| 
       29 
27 
     | 
    
         
             
                def clear
         
     | 
| 
       30 
28 
     | 
    
         
             
                  @options.clear
         
     | 
| 
       31 
29 
     | 
    
         
             
                end
         
     | 
| 
       32 
30 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                # Get results from the builtin in Hash.
         
     | 
| 
      
 32 
     | 
    
         
            +
                # @param [Symbol,String,nil] key Either a single key or nil for the entire hash.
         
     | 
| 
      
 33 
     | 
    
         
            +
                # @return [Hash] a hash, empty or otherwise.
         
     | 
| 
      
 34 
     | 
    
         
            +
                def [](key = nil)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  return @options[key] if key
         
     | 
| 
       35 
36 
     | 
    
         
             
                  return @options if @options.any?
         
     | 
| 
       36 
37 
     | 
    
         
             
                  {}
         
     | 
| 
       37 
38 
     | 
    
         
             
                end
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
                # Set a key/value pair in the buildin Hash.
         
     | 
| 
       39 
41 
     | 
    
         
             
                def []=(k,v)
         
     | 
| 
       40 
42 
     | 
    
         
             
                  @options[k] = v
         
     | 
| 
       41 
43 
     | 
    
         
             
                end
         
     | 
| 
         @@ -48,6 +50,8 @@ module Bini 
     | 
|
| 
       48 
50 
     | 
    
         
             
                  h.each {|k,v| self[k] = v}
         
     | 
| 
       49 
51 
     | 
    
         
             
                end
         
     | 
| 
       50 
52 
     | 
    
         
             
              end
         
     | 
| 
       51 
     | 
    
         
            -
               
     | 
| 
      
 53 
     | 
    
         
            +
              # An automatically created entry point into the OptionParser class.
         
     | 
| 
      
 54 
     | 
    
         
            +
              Options = Bini::OptionParser.new
         
     | 
| 
       52 
55 
     | 
    
         
             
            end
         
     | 
| 
       53 
56 
     | 
    
         | 
| 
      
 57 
     | 
    
         
            +
             
     | 
    
        data/lib/bini/prompts.rb
    CHANGED
    
    
    
        data/lib/bini/sash.rb
    CHANGED
    
    | 
         @@ -12,8 +12,6 @@ module Bini 
     | 
|
| 
       12 
12 
     | 
    
         
             
                attr_accessor :auto_load
         
     | 
| 
       13 
13 
     | 
    
         
             
                attr_accessor :auto_save
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
15 
     | 
    
         
             
                # initialization sets the values of the class Sash, not the contents of the Hash.
         
     | 
| 
       18 
16 
     | 
    
         
             
                def initialize(params = {})
         
     | 
| 
       19 
17 
     | 
    
         
             
                  params.each { |k,v| instance_variable_set "@" + k.to_s,v}
         
     | 
| 
         @@ -47,7 +45,7 @@ module Bini 
     | 
|
| 
       47 
45 
     | 
    
         
             
                  end
         
     | 
| 
       48 
46 
     | 
    
         
             
                  true
         
     | 
| 
       49 
47 
     | 
    
         
             
                end
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                # Store a value in the Hash.  Can autosave.
         
     | 
| 
       51 
49 
     | 
    
         
             
                def []=(key,value)
         
     | 
| 
       52 
50 
     | 
    
         
             
                  store key, value
         
     | 
| 
       53 
51 
     | 
    
         
             
                  save! if @auto_save == true
         
     | 
    
        data/lib/bini/version.rb
    CHANGED
    
    
| 
         @@ -2,14 +2,14 @@ require 'spec_helper' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            describe "Bini.config" do
         
     | 
| 
       4 
4 
     | 
    
         
             
            	it "is a hash." do
         
     | 
| 
       5 
     | 
    
         
            -
            		Bini. 
     | 
| 
      
 5 
     | 
    
         
            +
            		Bini::Config.kind_of?(Hash).should be_true
         
     | 
| 
       6 
6 
     | 
    
         
             
            	end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            	it "which responds to save" do
         
     | 
| 
       9 
     | 
    
         
            -
            		Bini. 
     | 
| 
      
 9 
     | 
    
         
            +
            		Bini::Config.respond_to?(:save).should be_true
         
     | 
| 
       10 
10 
     | 
    
         
             
            	end
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            	it "which responds to load" do
         
     | 
| 
       13 
     | 
    
         
            -
            		Bini. 
     | 
| 
      
 13 
     | 
    
         
            +
            		Bini::Config.respond_to?(:load).should be_true
         
     | 
| 
       14 
14 
     | 
    
         
             
            	end
         
     | 
| 
       15 
15 
     | 
    
         
             
            end
         
     | 
| 
         @@ -4,4 +4,8 @@ describe "FileMagic" do 
     | 
|
| 
       4 
4 
     | 
    
         
             
            	it "it will return a ruby mime type when targeting a ruby file." do
         
     | 
| 
       5 
5 
     | 
    
         
             
            		Bini::FileMagic.mime_type("./lib/bini.rb").should eq "text/x-ruby"
         
     | 
| 
       6 
6 
     | 
    
         
             
            	end
         
     | 
| 
      
 7 
     | 
    
         
            +
              it "will return the version of file if needed" do
         
     | 
| 
      
 8 
     | 
    
         
            +
                s = Bini::FileMagic.module_exec {filemagic_version}
         
     | 
| 
      
 9 
     | 
    
         
            +
                `file -v`.include?(s).should be_true
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
       7 
11 
     | 
    
         
             
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -39,13 +39,17 @@ describe "optparser" do 
     | 
|
| 
       39 
39 
     | 
    
         
             
            			Options.mash h
         
     | 
| 
       40 
40 
     | 
    
         
             
            			Options[:mash].should eq 'mush'
         
     | 
| 
       41 
41 
     | 
    
         
             
            		end
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
42 
     | 
    
         
             
            	end
         
     | 
| 
       44 
43 
     | 
    
         
             
            	describe "parse" do
         
     | 
| 
       45 
44 
     | 
    
         
             
            		it "will attempt to mash in the Config[]#hash if available." do
         
     | 
| 
       46 
     | 
    
         
            -
            			Bini:: 
     | 
| 
      
 45 
     | 
    
         
            +
            			Bini::Config[@key] == @value
         
     | 
| 
       47 
46 
     | 
    
         
             
            			Options.parse!
         
     | 
| 
       48 
47 
     | 
    
         
             
            			Options[@key] = @value
         
     | 
| 
       49 
48 
     | 
    
         
             
            		end
         
     | 
| 
      
 49 
     | 
    
         
            +
            		it "Will echo the version set by Bini.version" do
         
     | 
| 
      
 50 
     | 
    
         
            +
            			Bini.version = "v0.0.0"
         
     | 
| 
      
 51 
     | 
    
         
            +
            			$stdout.should_receive(:puts).with(Bini.version)
         
     | 
| 
      
 52 
     | 
    
         
            +
            			Options.parse ["-V"]
         
     | 
| 
      
 53 
     | 
    
         
            +
            		end
         
     | 
| 
       50 
54 
     | 
    
         
             
            	end
         
     | 
| 
       51 
55 
     | 
    
         
             
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # I'm not 100% sure convinvced any of these do what I think they do.
         
     | 
| 
      
 4 
     | 
    
         
            +
            describe "Bini" do
         
     | 
| 
      
 5 
     | 
    
         
            +
            	before (:each) do
         
     | 
| 
      
 6 
     | 
    
         
            +
            		Bini.long_name = nil
         
     | 
| 
      
 7 
     | 
    
         
            +
            		@long_name = Bini.long_name
         
     | 
| 
      
 8 
     | 
    
         
            +
            		Bini.cache_dir = nil
         
     | 
| 
      
 9 
     | 
    
         
            +
            		@cache_dir = Bini.cache_dir
         
     | 
| 
      
 10 
     | 
    
         
            +
            		Bini.config_dir = nil
         
     | 
| 
      
 11 
     | 
    
         
            +
            		@config_dir = Bini.config_dir
         
     | 
| 
      
 12 
     | 
    
         
            +
            		Bini.version = nil
         
     | 
| 
      
 13 
     | 
    
         
            +
            	end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            	describe "parameters?" do
         
     | 
| 
      
 16 
     | 
    
         
            +
            		it 'will return true only if everything is true.' do
         
     | 
| 
      
 17 
     | 
    
         
            +
            			Bini.long_name = "tmp/test"
         
     | 
| 
      
 18 
     | 
    
         
            +
            			Bini.parameters?.should be_false
         
     | 
| 
      
 19 
     | 
    
         
            +
            			Bini.cache_dir = "tmp/here"
         
     | 
| 
      
 20 
     | 
    
         
            +
            			Bini.config_dir = "tmp/there"
         
     | 
| 
      
 21 
     | 
    
         
            +
            			Bini.parameters?.should be_true
         
     | 
| 
      
 22 
     | 
    
         
            +
            		end
         
     | 
| 
      
 23 
     | 
    
         
            +
            	end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            	# Dynamically generate our key tests, more for fun then any real need.
         
     | 
| 
      
 26 
     | 
    
         
            +
            	Bini.keys.each do |key|
         
     | 
| 
      
 27 
     | 
    
         
            +
            		describe "#{key}" do
         
     | 
| 
      
 28 
     | 
    
         
            +
            			it "can be reset to a default" do
         
     | 
| 
      
 29 
     | 
    
         
            +
            				Bini.send "#{key}=", nil
         
     | 
| 
      
 30 
     | 
    
         
            +
            				Bini.send(key).should eq Bini.defaults[key]
         
     | 
| 
      
 31 
     | 
    
         
            +
            			end
         
     | 
| 
      
 32 
     | 
    
         
            +
            			it "can be overriden" do
         
     | 
| 
      
 33 
     | 
    
         
            +
            				r = random_hex 16
         
     | 
| 
      
 34 
     | 
    
         
            +
            				Bini.send "#{key}=", r
         
     | 
| 
      
 35 
     | 
    
         
            +
            				Bini.send(key).should eq r
         
     | 
| 
      
 36 
     | 
    
         
            +
            			end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            			it "can be configured via .configure" do
         
     | 
| 
      
 39 
     | 
    
         
            +
            				r = random_hex 4
         
     | 
| 
      
 40 
     | 
    
         
            +
            				Bini.configure do |c|
         
     | 
| 
      
 41 
     | 
    
         
            +
            					c.instance_variable_set "@#{key}", r
         
     | 
| 
      
 42 
     | 
    
         
            +
            				end
         
     | 
| 
      
 43 
     | 
    
         
            +
            				Bini.send(key).should eq r
         
     | 
| 
      
 44 
     | 
    
         
            +
            			end
         
     | 
| 
      
 45 
     | 
    
         
            +
            		end
         
     | 
| 
      
 46 
     | 
    
         
            +
            	end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            	Bini.version
         
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bini
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.6.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-12-18 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: sys-proctable
         
     | 
| 
         @@ -37,6 +37,8 @@ files: 
     | 
|
| 
       37 
37 
     | 
    
         
             
            - .gitignore
         
     | 
| 
       38 
38 
     | 
    
         
             
            - .rspec
         
     | 
| 
       39 
39 
     | 
    
         
             
            - .travis.yml
         
     | 
| 
      
 40 
     | 
    
         
            +
            - .yardopts
         
     | 
| 
      
 41 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       40 
42 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       41 
43 
     | 
    
         
             
            - Guardfile
         
     | 
| 
       42 
44 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
         @@ -51,12 +53,12 @@ files: 
     | 
|
| 
       51 
53 
     | 
    
         
             
            - lib/bini/prompts.rb
         
     | 
| 
       52 
54 
     | 
    
         
             
            - lib/bini/sash.rb
         
     | 
| 
       53 
55 
     | 
    
         
             
            - lib/bini/version.rb
         
     | 
| 
       54 
     | 
    
         
            -
            - spec/ 
     | 
| 
       55 
     | 
    
         
            -
            - spec/ 
     | 
| 
       56 
     | 
    
         
            -
            - spec/ 
     | 
| 
       57 
     | 
    
         
            -
            - spec/ 
     | 
| 
       58 
     | 
    
         
            -
            - spec/ 
     | 
| 
       59 
     | 
    
         
            -
            - spec/ 
     | 
| 
      
 56 
     | 
    
         
            +
            - spec/lib/bini/config_spec.rb
         
     | 
| 
      
 57 
     | 
    
         
            +
            - spec/lib/bini/filemagic_spec.rb
         
     | 
| 
      
 58 
     | 
    
         
            +
            - spec/lib/bini/mixins_spec.rb
         
     | 
| 
      
 59 
     | 
    
         
            +
            - spec/lib/bini/optparser_spec.rb
         
     | 
| 
      
 60 
     | 
    
         
            +
            - spec/lib/bini/sash_spec.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - spec/lib/bini_spec.rb
         
     | 
| 
       60 
62 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       61 
63 
     | 
    
         
             
            homepage: https://github.com/erniebrodeur/bini
         
     | 
| 
       62 
64 
     | 
    
         
             
            licenses: []
         
     | 
| 
         @@ -70,18 +72,12 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       70 
72 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       71 
73 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       72 
74 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       73 
     | 
    
         
            -
                  segments:
         
     | 
| 
       74 
     | 
    
         
            -
                  - 0
         
     | 
| 
       75 
     | 
    
         
            -
                  hash: -581091682006893014
         
     | 
| 
       76 
75 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       77 
76 
     | 
    
         
             
              none: false
         
     | 
| 
       78 
77 
     | 
    
         
             
              requirements:
         
     | 
| 
       79 
78 
     | 
    
         
             
              - - ! '>='
         
     | 
| 
       80 
79 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       81 
80 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       82 
     | 
    
         
            -
                  segments:
         
     | 
| 
       83 
     | 
    
         
            -
                  - 0
         
     | 
| 
       84 
     | 
    
         
            -
                  hash: -581091682006893014
         
     | 
| 
       85 
81 
     | 
    
         
             
            requirements: []
         
     | 
| 
       86 
82 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       87 
83 
     | 
    
         
             
            rubygems_version: 1.8.21
         
     | 
| 
         @@ -91,11 +87,11 @@ summary: Bini is a gem that helps me build CLI tools.  It's not thor, trollop, o 
     | 
|
| 
       91 
87 
     | 
    
         
             
              any of the other major frameworks.  It makes lots and lots of assumptions.  It's
         
     | 
| 
       92 
88 
     | 
    
         
             
              probably not for you.
         
     | 
| 
       93 
89 
     | 
    
         
             
            test_files:
         
     | 
| 
       94 
     | 
    
         
            -
            - spec/ 
     | 
| 
       95 
     | 
    
         
            -
            - spec/ 
     | 
| 
       96 
     | 
    
         
            -
            - spec/ 
     | 
| 
       97 
     | 
    
         
            -
            - spec/ 
     | 
| 
       98 
     | 
    
         
            -
            - spec/ 
     | 
| 
       99 
     | 
    
         
            -
            - spec/ 
     | 
| 
      
 90 
     | 
    
         
            +
            - spec/lib/bini/config_spec.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - spec/lib/bini/filemagic_spec.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - spec/lib/bini/mixins_spec.rb
         
     | 
| 
      
 93 
     | 
    
         
            +
            - spec/lib/bini/optparser_spec.rb
         
     | 
| 
      
 94 
     | 
    
         
            +
            - spec/lib/bini/sash_spec.rb
         
     | 
| 
      
 95 
     | 
    
         
            +
            - spec/lib/bini_spec.rb
         
     | 
| 
       100 
96 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       101 
97 
     | 
    
         
             
            has_rdoc: 
         
     | 
    
        data/spec/bini_spec.rb
    DELETED
    
    | 
         @@ -1,92 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # I'm not 100% sure convinvced any of these do what I think they do.
         
     | 
| 
       4 
     | 
    
         
            -
            describe "Bini" do
         
     | 
| 
       5 
     | 
    
         
            -
            	before (:each) do
         
     | 
| 
       6 
     | 
    
         
            -
            		Bini.long_name = nil
         
     | 
| 
       7 
     | 
    
         
            -
            		@long_name = Bini.long_name
         
     | 
| 
       8 
     | 
    
         
            -
            		Bini.cache_dir = nil
         
     | 
| 
       9 
     | 
    
         
            -
            		@cache_dir = Bini.cache_dir
         
     | 
| 
       10 
     | 
    
         
            -
            		Bini.config_dir = nil
         
     | 
| 
       11 
     | 
    
         
            -
            		@config_dir = Bini.config_dir
         
     | 
| 
       12 
     | 
    
         
            -
            	end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            	# I can probably do this dynamically.
         
     | 
| 
       15 
     | 
    
         
            -
            	describe "long_name" do
         
     | 
| 
       16 
     | 
    
         
            -
            		it "can be reset" do
         
     | 
| 
       17 
     | 
    
         
            -
            			Bini.long_name = nil
         
     | 
| 
       18 
     | 
    
         
            -
            			Bini.long_name.should eq Bini.defaults[:long_name]
         
     | 
| 
       19 
     | 
    
         
            -
            		end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            		it "provides a default" do
         
     | 
| 
       22 
     | 
    
         
            -
            			Bini.long_name = nil
         
     | 
| 
       23 
     | 
    
         
            -
            			Bini.long_name.should_not be_nil
         
     | 
| 
       24 
     | 
    
         
            -
            		end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            		it "can be overridden" do
         
     | 
| 
       27 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       28 
     | 
    
         
            -
            			Bini.long_name = r
         
     | 
| 
       29 
     | 
    
         
            -
            			Bini.long_name.should eq r
         
     | 
| 
       30 
     | 
    
         
            -
            		end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
            		it "can be configured via .configure" do
         
     | 
| 
       33 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       34 
     | 
    
         
            -
            			Bini.configure do |c|
         
     | 
| 
       35 
     | 
    
         
            -
            				c.long_name = r
         
     | 
| 
       36 
     | 
    
         
            -
            			end
         
     | 
| 
       37 
     | 
    
         
            -
            			Bini.long_name.should eq r
         
     | 
| 
       38 
     | 
    
         
            -
            		end
         
     | 
| 
       39 
     | 
    
         
            -
            	end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
            	describe "cache_dir" do
         
     | 
| 
       42 
     | 
    
         
            -
            		it "can be reset" do
         
     | 
| 
       43 
     | 
    
         
            -
            			Bini.cache_dir = nil
         
     | 
| 
       44 
     | 
    
         
            -
            			Bini.cache_dir.should eq @cache_dir
         
     | 
| 
       45 
     | 
    
         
            -
            		end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
            		it "provides a default" do
         
     | 
| 
       49 
     | 
    
         
            -
            			Bini.cache_dir = nil
         
     | 
| 
       50 
     | 
    
         
            -
            			Bini.cache_dir.should_not be_nil
         
     | 
| 
       51 
     | 
    
         
            -
            		end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
            		it "can be overridden" do
         
     | 
| 
       54 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       55 
     | 
    
         
            -
            			Bini.cache_dir = r
         
     | 
| 
       56 
     | 
    
         
            -
            			Bini.cache_dir.should eq r
         
     | 
| 
       57 
     | 
    
         
            -
            		end
         
     | 
| 
       58 
     | 
    
         
            -
            		it "can be configured via .configure" do
         
     | 
| 
       59 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       60 
     | 
    
         
            -
            			Bini.configure do |c|
         
     | 
| 
       61 
     | 
    
         
            -
            				c.cache_dir = r
         
     | 
| 
       62 
     | 
    
         
            -
            			end
         
     | 
| 
       63 
     | 
    
         
            -
            			Bini.cache_dir.should eq r
         
     | 
| 
       64 
     | 
    
         
            -
            		end
         
     | 
| 
       65 
     | 
    
         
            -
            	end
         
     | 
| 
       66 
     | 
    
         
            -
            	describe "config_dir" do
         
     | 
| 
       67 
     | 
    
         
            -
            		it "can be reset" do
         
     | 
| 
       68 
     | 
    
         
            -
            			Bini.config_dir = nil
         
     | 
| 
       69 
     | 
    
         
            -
            			Bini.config_dir.should eq @config_dir
         
     | 
| 
       70 
     | 
    
         
            -
            		end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
            		it "provides a default" do
         
     | 
| 
       74 
     | 
    
         
            -
            			Bini.config_dir = nil
         
     | 
| 
       75 
     | 
    
         
            -
            			Bini.config_dir.should_not be_nil
         
     | 
| 
       76 
     | 
    
         
            -
            		end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
            		it "can be overridden" do
         
     | 
| 
       79 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       80 
     | 
    
         
            -
            			Bini.config_dir = r
         
     | 
| 
       81 
     | 
    
         
            -
            			Bini.config_dir.should eq r
         
     | 
| 
       82 
     | 
    
         
            -
            		end
         
     | 
| 
       83 
     | 
    
         
            -
            		it "can be configured via .configure" do
         
     | 
| 
       84 
     | 
    
         
            -
            			r = random_hex 4
         
     | 
| 
       85 
     | 
    
         
            -
            			Bini.configure do |c|
         
     | 
| 
       86 
     | 
    
         
            -
            				c.config_dir = r
         
     | 
| 
       87 
     | 
    
         
            -
            			end
         
     | 
| 
       88 
     | 
    
         
            -
            			Bini.config_dir.should eq r
         
     | 
| 
       89 
     | 
    
         
            -
            		end
         
     | 
| 
       90 
     | 
    
         
            -
            	end
         
     | 
| 
       91 
     | 
    
         
            -
            end
         
     | 
| 
       92 
     | 
    
         
            -
             
     |