clipar 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/clipar.gemspec +28 -0
- data/lib/clipar/version.rb +3 -0
- data/lib/clipar.rb +57 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9f1c4bed6856b0c1a7a859481cb6efbe71f3c43
|
4
|
+
data.tar.gz: 05b64309d3921f5a7996472d2322731181640efd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0e86ebecbb8285cbad07ba2dfd1839bbf2ede93a0881210be8acbc3632975987871a9c43cac61394c833a987903072bb5a1ae9ba208fe58995dde50797b2ac4
|
7
|
+
data.tar.gz: b99d5114aeac231d64cde8813079f32d1beffa0155867b4f74462aec21f9cda97eb796ecab22662b8a793c42e0c656da2d2e76ea21e3fb8f91545a1a3065dfa9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Clipar
|
2
|
+
|
3
|
+
Get command line paramenters on your code easily. Treat them as methods of an object
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'clipar'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install clipar
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
If you want to pass values to your code from command line like
|
24
|
+
|
25
|
+
```
|
26
|
+
cucumber foo=bar
|
27
|
+
```
|
28
|
+
|
29
|
+
You can do this with CLIPar:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'clipar'
|
33
|
+
|
34
|
+
cli = CLIPar.new
|
35
|
+
cli.foo
|
36
|
+
# => "bar"
|
37
|
+
|
38
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "clipar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/clipar.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "clipar/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "clipar"
|
8
|
+
spec.version = Clipar::VERSION
|
9
|
+
spec.authors = ["Roman"]
|
10
|
+
spec.email = ["roman.g.rodriguez@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Handle command line parameters as methods within your code}
|
13
|
+
spec.description = %q{Easy way to pass arguments over command line and get them from your code}
|
14
|
+
spec.homepage = ""
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
data/lib/clipar.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "clipar/version"
|
2
|
+
|
3
|
+
|
4
|
+
class CLIPar
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
detect_os
|
8
|
+
parse_args
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_args
|
12
|
+
if win?
|
13
|
+
@env = {}
|
14
|
+
ARGV.each do |arg|
|
15
|
+
key_val = arg.split("=")
|
16
|
+
@env[key_val.first]= key_val.last
|
17
|
+
end
|
18
|
+
else
|
19
|
+
@env = ENV
|
20
|
+
end
|
21
|
+
@env
|
22
|
+
end
|
23
|
+
|
24
|
+
def detect_os
|
25
|
+
@os = case RUBY_PLATFORM
|
26
|
+
when /cygwin|mswin|mingw|bccwin|wince|emx/
|
27
|
+
:windows
|
28
|
+
when /darwin/
|
29
|
+
:mac
|
30
|
+
else
|
31
|
+
:linux
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def win?
|
36
|
+
@os == :windows
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_param name, value, force=false
|
40
|
+
return nil if win?
|
41
|
+
unless force
|
42
|
+
raise "Param '#{name}' already exists" if @env.keys.include? name
|
43
|
+
end
|
44
|
+
@env[name]= value
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Any parameter name passed through command line will be trated as a method
|
49
|
+
def method_missing meth
|
50
|
+
if win?
|
51
|
+
|
52
|
+
else
|
53
|
+
@env["#{meth}"]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clipar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Easy way to pass arguments over command line and get them from your code
|
42
|
+
email:
|
43
|
+
- roman.g.rodriguez@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- clipar.gemspec
|
56
|
+
- lib/clipar.rb
|
57
|
+
- lib/clipar/version.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.6.14
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Handle command line parameters as methods within your code
|
81
|
+
test_files: []
|