argv 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +41 -0
  4. data/VERSION +1 -1
  5. data/lib/argv.rb +46 -8
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fea51db2a656fdcf77062c0255c79d79575ef76a
4
- data.tar.gz: 1081c980988c52fe0c13cede7b26c6f5f7c66bbb
3
+ metadata.gz: 9bc8f2bf35c658b1039a558b3ade585f7d9f7efc
4
+ data.tar.gz: a7a769f338a6106b75aa9169906fccab98efebed
5
5
  SHA512:
6
- metadata.gz: 5dcb7d657bdf8a9fcc1ac1e27c44f3cd9a2f053ecdf129f15a6d8664da3061f087b34e238901873803f11333b74dabf0cea530fe598d43cf9579cb908ed902d6
7
- data.tar.gz: 72a2a8d0c44f80529db5faf5badaad37d01da7ed67177f1736fcb58937c020333dba96347f93615b26fb314571e474742eea01dcfcdb9e125af84091a8cc81c1
6
+ metadata.gz: 8bab7e3eb9a01d5f2ecab5cceb9d519942dd2cc55308a3a3c09f006c29e8c4c6296f49350aa6167b87738ead1747c131c9cbc62e9bae9571dc03d60853dddf32
7
+ data.tar.gz: e73767cda42b3bb00f3cc0bb00191ee18a6416a31d3c946388cca3f979bb6f97d08b8c321b29fa1f6c84f02b6e96d2b2594fe3b6d8c491bcff24e028bdb8c5c5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- argv (1.0.0)
4
+ argv (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -8,6 +8,8 @@ With this extension module, you can parse in an easy way the script input tags
8
8
 
9
9
  ```ruby
10
10
 
11
+ require 'argv'
12
+
11
13
  #> $ script.rb --test this --hello world --sup
12
14
 
13
15
  puts ARGV.flag_tags
@@ -16,4 +18,43 @@ With this extension module, you can parse in an easy way the script input tags
16
18
  puts ARGV.flags.inspect
17
19
  # ["--test", "--hello", "--sup"]
18
20
 
21
+ ```
22
+
23
+ ```ruby
24
+
25
+
26
+ #> $ script.rb --test this --hello world --su-p asd sdsd -asd -dsa
27
+
28
+ puts ARGV.values.inspect
29
+ #> ["this", "world", "asd", "sdsd"]
30
+
31
+ puts ARGV.flagtags sym_key: true
32
+ #> {:test=>"this", :hello=>"world", :"su-p"=>"asd"}
33
+
34
+
35
+ ```
36
+
37
+ ```ruby
38
+
39
+
40
+ #> $ script.rb --test this this multi value --hello world asdf
41
+
42
+ puts ARGV.values.inspect
43
+ #> ["this", "world", "asd", "sdsd"]
44
+
45
+ puts ARGV.flagtags sym_key: true
46
+ #> {:test=>"this", :hello=>"world", :"su-p"=>"asd"}
47
+
48
+
49
+ ```
50
+
51
+ ### multi value use case
52
+
53
+ ```ruby
54
+
55
+ #> $ script.rb --test this --hello world --su-p asd sdsd -asd -dsa
56
+
57
+ puts ARGV.flag_multi_value.inspect
58
+ #> {"--test"=>["this"], "--hello"=>["world"], "--su-p"=>["asd", "sdsd"]}
59
+
19
60
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/lib/argv.rb CHANGED
@@ -1,6 +1,32 @@
1
1
  module ARGVEXT
2
2
 
3
- def flag_tags
3
+ def flag_tags opts= {}
4
+ raise(ArgumentError) unless opts.class <= Hash
5
+
6
+ opts[:sym_key] ||= opts[:sym] || opts[:sk] || opts[:s]
7
+
8
+ return_obj= {}
9
+ self.count.times do |index|
10
+
11
+ next if self[index+1].nil?
12
+ if self[index][0].include?('-') && !self[index+1][0].include?('-')
13
+ return_obj[( opts[:sym_key] ? self[index].dup.to_s.gsub!(/^-*/,'').to_sym : self[index] )]= self[index+1]
14
+ end
15
+
16
+ end
17
+ return return_obj
18
+
19
+ end
20
+ alias :flag_value :flag_tags
21
+ alias :flag_tag :flag_tags
22
+ alias :flagtag :flag_tags
23
+ alias :flagtags :flag_tags
24
+
25
+ def flag_multi_value opts= {}
26
+ raise(ArgumentError) unless opts.class <= Hash
27
+
28
+ opts[:sym_key] ||= opts[:sym] || opts[:sk] || opts[:s]
29
+
4
30
 
5
31
  return_obj= {}
6
32
  self.count.times do |index|
@@ -8,7 +34,19 @@ module ARGVEXT
8
34
  begin
9
35
 
10
36
  if self[index][0].include?('-') && !self[index+1][0].include?('-')
11
- return_obj[self[index]]= self[index+1]
37
+
38
+ new_element= []
39
+ index_at= index+1
40
+ loop do
41
+ if self[index_at].nil? || self[index_at].to_s[0].include?('-')
42
+ break
43
+ else
44
+ new_element.push(self[index_at])
45
+ end
46
+ index_at += 1
47
+ end
48
+ return_obj[( opts[:sym_key] ? self[index].dup.to_s.gsub!(/^-*/,'').to_sym : self[index] )]= new_element
49
+
12
50
  end
13
51
 
14
52
  rescue
@@ -18,15 +56,15 @@ module ARGVEXT
18
56
  return return_obj
19
57
 
20
58
  end
21
- alias :flag_tag :flag_tags
22
- alias :flagtag :flag_tags
23
- alias :flagtags :flag_tags
24
59
 
25
60
  def flags
26
- self.select{ |e| e[0].include?('-') }
61
+ self.select { |e| e[0].include?('-') }
27
62
  end
28
63
 
29
- end
64
+ def values
65
+ self.select { |e| !e[0].include?('-') }
66
+ end
30
67
 
31
- ARGV.__send__ :extend,ARGVEXT
68
+ end
32
69
 
70
+ ARGV.__send__ :extend,ARGVEXT
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi