arg0 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ ##### v0.0.3
2
+
3
+ feature updates, tests added
4
+ [+] Arg0::Consoe.keyring # to fetch hash of all arguments (refer: README.md)
5
+ [+] Arg0::Console.values # alias to value_for, returns array of available values
6
+ [+] Arg0::Console.value # singular to value_for, returns first available value or nil
7
+
1
8
  ##### v0.0.2
2
9
 
3
10
  multiple synoymous arguments to be fetched
data/README.md CHANGED
@@ -18,19 +18,42 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- to load it up
21
+ * to load it up
22
22
 
23
23
  require 'arg0'
24
24
 
25
- to check if a bool-type switch is provided
25
+ * to check if a bool-type switch is provided
26
26
 
27
27
  Arg0::Console.switch?('--is-arg')
28
28
  Arg0::Console.switch?(['-isarg', '--is-arg']) # synonymous args
29
29
 
30
- returning array of (empty or) Value(s) provided after --my-arg at ARGV
30
+ * returning array of (empty or) Value(s) provided after --my-arg at ARGV
31
31
 
32
32
  Arg0::Console.value_for('--my-arg')
33
+ is same as Arg0::Console.values('--my-arg')
34
+
35
+ >
36
+
33
37
  Arg0::Console.value_for(['-myarg', '--my-arg']) # synonymous args
38
+ is same as Arg0::Console.values(['-myarg', '--my-arg'])
39
+
40
+
41
+ * returning the first value (not array of all) for any switch
42
+
43
+ Arg0::Console.value('--my-arg')
44
+ Arg0::Console.value(['-myarg', '--my-arg']) # synonymous args
45
+
46
+
47
+ * returning Hash for all the Arguments provided as argument on console
48
+
49
+ suppose command run was
50
+ $ arg0_based_cmd -src ./lib -type html -v -l ./log/app.log start
51
+
52
+ >
53
+
54
+ Arg0::Console.keyring
55
+ # will return {'-src' => './lib', '-type' => 'html', '-v' => true, '-l' => './log/app', 'start' => :data }
56
+
34
57
 
35
58
  ## Contributing
36
59
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/test*.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -1,5 +1,5 @@
1
1
  # arg0
2
- arg0_libs = File.join(File.dirname(File.expand_path __FILE__), 'ci-go-nfo', '*.rb')
2
+ arg0_libs = File.join(File.dirname(File.expand_path __FILE__), 'arg0', '*.rb')
3
3
  Dir.glob(arg0_libs).each do |lib|
4
4
  require lib
5
5
  end
@@ -22,5 +22,31 @@ module Arg0
22
22
  values.delete nil
23
23
  values
24
24
  end
25
+
26
+ class << self; alias values value_for; end
27
+
28
+ def self.value(switch_name)
29
+ ARGV.each_with_index {|arg, index|
30
+ if [switch_name].flatten.include? arg
31
+ return ARGV[index + 1]
32
+ end
33
+ }
34
+ nil
35
+ end
36
+
37
+ def self.keyring
38
+ key_vals = {}
39
+ ARGV.each {|arg|
40
+ last_key = key_vals.keys.last
41
+ if arg.match(/^-.*/)
42
+ key_vals[arg] = true
43
+ elsif key_vals[last_key] == true
44
+ key_vals[last_key] = arg
45
+ else
46
+ key_vals[arg] = :data
47
+ end
48
+ }
49
+ key_vals
50
+ end
25
51
  end
26
52
  end
@@ -1,3 +1,3 @@
1
1
  module Arg0
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require_relative '../lib/arg0.rb'
5
+
6
+ class TestArg0Console < Test::Unit::TestCase
7
+ def setup; end
8
+ def teardown; ARGV.clear; end
9
+
10
+ def test_switch_empty
11
+ assert_equal Arg0::Console.switch?('-h'), false
12
+ end
13
+
14
+ def test_switch_on
15
+ ARGV.push '-h'
16
+ assert_equal Arg0::Console.switch?('-h'), true
17
+ assert_equal Arg0::Console.switch?(['-h', '--help']), true
18
+ assert_equal Arg0::Console.switch?(['-info', '-h', '--help']), true
19
+ end
20
+
21
+ def test_switch_off
22
+ ARGV.push '--help'
23
+ assert_equal Arg0::Console.switch?('-h'), false
24
+ assert_equal Arg0::Console.switch?(['-h', '-help']), false
25
+ end
26
+
27
+ def test_value_for
28
+ assert_equal Arg0::Console.value_for('-src'), []
29
+ ARGV.push '--log', 'a0.log', '-src', File.dirname(__FILE__), '-v', '-l', 'a2.log'
30
+ src01 = Arg0::Console.value_for('-src')
31
+ src02 = Arg0::Console.value_for(['-s', '-src', '--source'])
32
+ log = Arg0::Console.value_for(['-l', '--log'])
33
+ assert_equal src01, src02
34
+ assert_not_equal src01, log
35
+ assert_equal log, ['a0.log', 'a2.log']
36
+ end
37
+
38
+ def test_values
39
+ ARGV.push '--log', 'a0.log', '-src', File.dirname(__FILE__), '-v', '-l', 'a2.log'
40
+ src01 = Arg0::Console.values('-src')
41
+ src02 = Arg0::Console.values(['-s', '-src', '--source'])
42
+ log = Arg0::Console.values(['-l', '--log'])
43
+ assert_equal src01, src02
44
+ assert_not_equal src01, log
45
+ assert_equal log, ['a0.log', 'a2.log']
46
+ end
47
+
48
+ def test_value
49
+ assert_equal Arg0::Console.value(['-l', '--log']), nil
50
+ ARGV.push '--log', 'a0.log', '-src', File.dirname(__FILE__), '-v', '-l', 'a2.log'
51
+ assert_equal Arg0::Console.value(['-l', '--log']), 'a0.log'
52
+ end
53
+
54
+ def test_keyring
55
+ assert_equal Arg0::Console.keyring, {}
56
+ ARGV.push '--log', 'a0.log', '-src', File.dirname(__FILE__), '-v', '-l', 'a2.log'
57
+ key_vals = Arg0::Console.keyring
58
+ assert_equal key_vals, {"--log"=>"a0.log", "-src"=>File.dirname(__FILE__), "-v"=>true, "-l"=>"a2.log"}
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arg0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: It's just here to handle arguments provided to Application. Mainly optional
15
15
  via switches. Currently handles plain-text Console arguments.
@@ -28,6 +28,7 @@ files:
28
28
  - arg0.gemspec
29
29
  - lib/arg0.rb
30
30
  - lib/arg0/version.rb
31
+ - test/test_arg0_console.rb
31
32
  homepage: https://github.com/abhishekkr/arg0
32
33
  licenses: []
33
34
  post_install_message:
@@ -52,4 +53,6 @@ rubygems_version: 1.8.24
52
53
  signing_key:
53
54
  specification_version: 3
54
55
  summary: Arg0 is here to handle the ARGs passed to your application.
55
- test_files: []
56
+ test_files:
57
+ - test/test_arg0_console.rb
58
+ has_rdoc: