clik 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.index ADDED
@@ -0,0 +1,69 @@
1
+ ---
2
+ revision: 2013
3
+ type: ruby
4
+ sources:
5
+ - var
6
+ authors:
7
+ - name: Trans
8
+ email: transfire@gmail.com
9
+ organizations:
10
+ - name: Rubyworks
11
+ requirements:
12
+ - groups:
13
+ - build
14
+ development: true
15
+ name: detroit
16
+ - groups:
17
+ - build
18
+ development: true
19
+ name: ergo
20
+ - groups:
21
+ - test
22
+ development: true
23
+ name: qed
24
+ - groups:
25
+ - test
26
+ development: true
27
+ name: ae
28
+ conflicts: []
29
+ alternatives: []
30
+ resources:
31
+ - type: home
32
+ uri: http://rubyworks.github.com/clik
33
+ label: Homepage
34
+ - type: code
35
+ uri: http://github.com/rubyworks/clik
36
+ label: Source Code
37
+ - type: docs
38
+ uri: http://rubydoc.info/gems/clik
39
+ label: Documentation
40
+ - type: wiki
41
+ uri: http://wiki.github.com/rubyworks/clik
42
+ label: User Guide
43
+ - type: bugs
44
+ uri: http://github.com/rubyworks/clik/issues
45
+ label: Issue Tracker
46
+ - type: mail
47
+ uri: http://groups.google.com/group/rubyworks-mailinglist
48
+ label: Mailing List
49
+ repositories:
50
+ - name: upstream
51
+ scm: git
52
+ uri: git://github.com/rubyworks/clik.git
53
+ categories: []
54
+ copyrights:
55
+ - holder: Rubyworks
56
+ year: '2013'
57
+ license: BSD-2-Clause
58
+ customs: []
59
+ paths:
60
+ lib:
61
+ - lib
62
+ created: '2013-01-01'
63
+ summary: Command-line Interface in the Kernel
64
+ title: CLI.K
65
+ version: 0.1.0
66
+ name: clik
67
+ description: ! "CLI.K stands for Command Line Interface in the Kernel. It provides
68
+ a very \nsimple `cli` method for parsing command line options."
69
+ date: '2013-03-07'
@@ -0,0 +1,9 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 0.1.0 / 2013-02-10
4
+
5
+ This is this is the first release of CLI.K. Happy releaseday!
6
+
7
+ Changes:
8
+
9
+ * All of them ;)
@@ -0,0 +1,23 @@
1
+ (BSD-2-Clause License)
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
14
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
17
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
20
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
22
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
@@ -0,0 +1,22 @@
1
+ CLI.K is based on Clap by Michel Martens
2
+
3
+ Copyright (c) 2010 Michel Martens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
@@ -0,0 +1,93 @@
1
+ # CLI.K
2
+
3
+ [Website](http://rubyworks.github.com/clik) /
4
+ [Documentation](http://rubydoc.info/gems/clik/frames) /
5
+ [Report Issue](http://github.com/rubyworks/clik/issues) /
6
+ [Source Code](http://github.com/rubyworks/clik)    
7
+ [![Build Status](https://travis-ci.org/rubyworks/clik.png)](https://travis-ci.org/rubyworks/clik)
8
+ [![Gem Version](https://badge.fury.io/rb/clik.png)](http://badge.fury.io/rb/clik)
9
+
10
+
11
+ ## About
12
+
13
+ CLI.K stands for Command Line Interface in the Kernel. It provides a very
14
+ simple `cli` method for parsing command line options.
15
+
16
+
17
+ ## Usage
18
+
19
+ ### They call it "K.I.S.S."
20
+
21
+ Usage is very straightforward, although it might look a little odd at first
22
+ glance:
23
+
24
+ ```ruby
25
+ require 'clik'
26
+
27
+ cli '-f --file' => lambda{ |f| @file = f },
28
+ '-d --debug' => lambda{ $DEBUG = true },
29
+ '-h --help' => lambda{ show_help }
30
+ ```
31
+
32
+ There's very little to it really. The `cli` command simply maps command
33
+ line options to procedures which are used to process them. That's it.
34
+
35
+ In our example, notice that `-w` and `--whatever` are easily defined as
36
+ synonymous options. Simple. Then notice that the `-f/--file` option's
37
+ procedure takes an argument, so the command line option takes an argument
38
+ as well. Again simple.
39
+
40
+ The cli method has a few additional niceties. It can handle run-on flags,
41
+ i.e. `-abc` is the same as `-a -b -c`. And you can pass it an alternate
42
+ set of arguments to parse, as the first argument, to use something other
43
+ than the default `ARGV`.
44
+
45
+ ```ruby
46
+ argv = ['--testing']
47
+
48
+ cli argv,
49
+ ...
50
+ ```
51
+
52
+ ### You need help, no you really don't
53
+
54
+ At this point, you might be wonder about help output. Clearly there are
55
+ no descriptions given in our example. Well, guess what! It's really easy
56
+ to print something out yourself. In fact, if you really want to *do it right*,
57
+ create a manpage with [ronn](git://github.com/rtomayko/ronn.git) or
58
+ [md2man](https://github.com/sunaku/md2man), and impress your friends.
59
+ It's a much better approach then jamming all that verbiage into you command
60
+ line options parser code.
61
+
62
+ ### Ask and you shell receive
63
+
64
+ In addition to `cli` CLI.K include the `ask` method. This is a very simple
65
+ command line query method.
66
+
67
+ ans = ask "Are you nice? [Y/N]"
68
+
69
+ Other Ruby libraries have their own take on the #ask method, and this very
70
+ simple implementation can just as soon be overridden. No biggy. But it's nice
71
+ to have for simple use cases.
72
+
73
+
74
+ ## Acknowledgments
75
+
76
+ We have to give credit where credit is due. This interface is the great
77
+ achievement of Michel Martens, who created the original [Clap](https://github.com/soveran/clap)
78
+ library from which CLI.K evolved. Mr. Martens deserves high praise for this
79
+ design. It's not easy to realize that this level of simplicity is all one
80
+ really needs! Thank you, Michel!
81
+
82
+
83
+ ## Copyrights & License
84
+
85
+ CLI.K is copyrighted open-source software.
86
+
87
+ Copyright (c) 2013 Rubyworks
88
+
89
+ CLI.K is base on Michel Marten's Clap library.
90
+
91
+ Copyright (c) 2010 Michel Martens
92
+
93
+ See LICENSE.txt and NOTICE.txt files for details.
@@ -0,0 +1,2 @@
1
+ require 'ae'
2
+ require 'clik'
@@ -0,0 +1,25 @@
1
+ # CLI.K
2
+
3
+ CLI.K provides a kernel method.
4
+
5
+ opts = {}
6
+ argv = ['-x']
7
+
8
+ cli argv,
9
+ '-x' => lambda{ opts[:x] = true }
10
+
11
+ opts[:x].assert === true
12
+
13
+ Another example,
14
+
15
+ opts = {}
16
+ argv = ['-w', '-f', 'hello']
17
+
18
+ cli argv,
19
+ '-w --whatever' => ->{ opts[:w] = true },
20
+ '-f --file' => ->(f){ opts[:f] = f },
21
+ '-h --help' => ->{ puts "help" }
22
+
23
+ opts[:w].assert == true
24
+ opts[:f].assert == 'hello'
25
+
@@ -0,0 +1,56 @@
1
+ module Kernel
2
+ private
3
+ #
4
+ # CLI is based on Clap library
5
+ # Copyright (c) 2010 Michel Martens
6
+ #
7
+ def cli(*args)
8
+ opts = args.pop
9
+ argv = (args.first || ARGV).dup
10
+ args = []
11
+
12
+ # Split option aliases.
13
+ opts = opts.inject({}) do |h,(k,v)|
14
+ k.to_s.split(/\s+/).each{|o| h[o]=v}; h
15
+ end
16
+
17
+ # Convert single dash flags into multiple flags.
18
+ argv = argv.inject([]) do |a, v|
19
+ if v[0,1] == '-' && v[1,1] != '-'
20
+ a.concat(v[1..-1].chars.map{|c| "-#{c}"})
21
+ else
22
+ a << v
23
+ end
24
+ a
25
+ end
26
+
27
+ while argv.any?
28
+ item = argv.shift
29
+ flag = opts[item]
30
+
31
+ if flag
32
+ # Work around lambda semantics in 1.8.7.
33
+ arity = [flag.arity, 0].max
34
+
35
+ # Raise if there are not enough parameters
36
+ # available for the flag.
37
+ if argv.size < arity
38
+ raise ArgumentError
39
+ end
40
+
41
+ # Call the lambda with N items from argv,
42
+ # where N is the lambda's arity.
43
+ flag.call(*argv.shift(arity))
44
+ else
45
+
46
+ # Collect the items that don't correspond to
47
+ # flags.
48
+ args << item
49
+ end
50
+ end
51
+
52
+ # TODO: should we replace the argv given with args?
53
+
54
+ args
55
+ end
56
+ end
@@ -0,0 +1,69 @@
1
+ ---
2
+ revision: 2013
3
+ type: ruby
4
+ sources:
5
+ - var
6
+ authors:
7
+ - name: Trans
8
+ email: transfire@gmail.com
9
+ organizations:
10
+ - name: Rubyworks
11
+ requirements:
12
+ - groups:
13
+ - build
14
+ development: true
15
+ name: detroit
16
+ - groups:
17
+ - build
18
+ development: true
19
+ name: ergo
20
+ - groups:
21
+ - test
22
+ development: true
23
+ name: qed
24
+ - groups:
25
+ - test
26
+ development: true
27
+ name: ae
28
+ conflicts: []
29
+ alternatives: []
30
+ resources:
31
+ - type: home
32
+ uri: http://rubyworks.github.com/clik
33
+ label: Homepage
34
+ - type: code
35
+ uri: http://github.com/rubyworks/clik
36
+ label: Source Code
37
+ - type: docs
38
+ uri: http://rubydoc.info/gems/clik
39
+ label: Documentation
40
+ - type: wiki
41
+ uri: http://wiki.github.com/rubyworks/clik
42
+ label: User Guide
43
+ - type: bugs
44
+ uri: http://github.com/rubyworks/clik/issues
45
+ label: Issue Tracker
46
+ - type: mail
47
+ uri: http://groups.google.com/group/rubyworks-mailinglist
48
+ label: Mailing List
49
+ repositories:
50
+ - name: upstream
51
+ scm: git
52
+ uri: git://github.com/rubyworks/clik.git
53
+ categories: []
54
+ copyrights:
55
+ - holder: Rubyworks
56
+ year: '2013'
57
+ license: BSD-2-Clause
58
+ customs: []
59
+ paths:
60
+ lib:
61
+ - lib
62
+ created: '2013-01-01'
63
+ summary: Command-line Interface in the Kernel
64
+ title: CLI.K
65
+ version: 0.1.0
66
+ name: clik
67
+ description: ! "CLI.K stands for Command Line Interface in the Kernel. It provides
68
+ a very \nsimple `cli` method for parsing command line options."
69
+ date: '2013-03-07'
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clik
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trans
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: detroit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ergo
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: qed
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ae
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! "CLI.K stands for Command Line Interface in the Kernel. It provides
79
+ a very \nsimple `cli` method for parsing command line options."
80
+ email:
81
+ - transfire@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - NOTICE.txt
87
+ - HISTORY.md
88
+ - README.md
89
+ files:
90
+ - .index
91
+ - demo/applique/req.rb
92
+ - demo/clik.md
93
+ - lib/clik.yml
94
+ - lib/clik.rb
95
+ - LICENSE.txt
96
+ - HISTORY.md
97
+ - README.md
98
+ - NOTICE.txt
99
+ homepage: http://rubyworks.github.com/clik
100
+ licenses:
101
+ - BSD-2-Clause
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.24
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Command-line Interface in the Kernel
124
+ test_files: []
125
+ has_rdoc: