zabcon 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/libs/zabcon_globals.rb +22 -1
  2. data/zabcon.rb +7 -5
  3. metadata +4 -4
@@ -111,6 +111,9 @@ end
111
111
 
112
112
  class EnvVars < GlobalsBase
113
113
 
114
+ class NoConfig < Exception
115
+ end
116
+
114
117
  def initialize
115
118
  super()
116
119
  end
@@ -121,14 +124,32 @@ class EnvVars < GlobalsBase
121
124
  def load_config(overrides={})
122
125
  begin
123
126
  config_file = overrides["config_file"].nil? ? self["config_file"] : overrides["config_file"]
127
+
128
+ if config_file==:default
129
+ home_default=File::expand_path("~/zabcon.conf")
130
+ if File::exists?("zabcon.conf")
131
+ config_file="zabcon.conf"
132
+ elsif File::exists?(home_default)
133
+ config_file=home_default
134
+ self["config_file"]=home_default
135
+ else
136
+ raise NoConfig
137
+ end
138
+ end
139
+
124
140
  config = overrides["load_config"]==false ? # nil != false
125
- {} : ParseConfig.new(config_file).params
141
+ {} : ParseConfig.new(config_file).params
142
+
143
+
126
144
  # If we are not loading the config use an empty hash
127
145
  rescue Errno::EACCES
128
146
  if !(config_file=="zabcon.conf" and !File::exists?(config_file))
129
147
  puts "Unable to access configuration file: #{config_file}"
130
148
  end
131
149
  config={}
150
+ rescue NoConfig
151
+ puts "Unable to find a default configuration file"
152
+ config={}
132
153
  end
133
154
 
134
155
  config.merge!(overrides) # merge the two option sets together but give precedence
data/zabcon.rb CHANGED
@@ -83,7 +83,8 @@ class ZabconApp
83
83
  @cmd_opts.help=true
84
84
  puts opts
85
85
  end
86
- opts.on("-l", "--load FILE", "load configuration file supplied or ","default if none") do |file|
86
+ opts.on("-l", "--load FILE", "load configuration file supplied or ","search the following default paths",
87
+ "./zabcon.conf, ~/zabcon.conf in that","order") do |file|
87
88
  @cmd_opts.config_file=file
88
89
  end
89
90
  opts.on("--no-config", "Do not attempt to automatically load","the configuration file") do
@@ -119,7 +120,7 @@ class ZabconApp
119
120
  env["logged_in"]=false
120
121
  env["have_tty"]=STDIN.tty?
121
122
  env["echo"]=STDIN.tty? ? true: false
122
- env["config_file"]="zabcon.conf"
123
+ env["config_file"]=:default
123
124
  env["load_config"]=true
124
125
 
125
126
  #output related environment variables
@@ -142,13 +143,13 @@ class ZabconApp
142
143
  items=ruby_rev.length < required_rev.length ? ruby_rev.length : required_rev.length
143
144
 
144
145
  for i in 0..items-1 do
145
- if ruby_rev[i]<required_rev[i]
146
+ if ruby_rev[i].to_i<required_rev[i].to_i
146
147
  puts
147
148
  puts "Zabcon requires Ruby version #{required_rev.join('.')} or higher."
148
149
  puts "you are using Ruby version #{RUBY_VERSION}."
149
150
  puts
150
151
  exit(1)
151
- elsif ruby_rev[i]>required_rev[i]
152
+ elsif ruby_rev[i].to_i>required_rev[i].to_i
152
153
  break
153
154
  end
154
155
  end
@@ -184,7 +185,9 @@ class ZabconApp
184
185
  h.each_pair do |k,v|
185
186
  cmd_hash[k.to_s]=v
186
187
  end
188
+
187
189
  EnvVars.instance.load_config(cmd_hash)
190
+
188
191
  rescue OptionParser::InvalidOption => e
189
192
  puts e
190
193
  puts
@@ -205,7 +208,6 @@ class ZabconApp
205
208
  puts RUBY_PLATFORM if EnvVars.instance["echo"]
206
209
 
207
210
  check_dependencies("1.8.6","parseconfig", "json", "highline")
208
- #check_dependencies("0.0.0","parseconfig", "json", "highline")
209
211
 
210
212
  begin
211
213
  require 'readline'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabcon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - A. Nelson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: .
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-28 00:00:00 -05:00
18
+ date: 2010-12-29 00:00:00 -05:00
19
19
  default_executable: zabcon
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency