cliqr 0.0.4 → 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 +4 -4
- data/CHANGELOG.md +207 -49
- data/README.md +8 -8
- data/lib/cliqr.rb +3 -3
- data/lib/cliqr/cli/argument_validator.rb +19 -0
- data/lib/cliqr/cli/command_context.rb +101 -0
- data/lib/cliqr/cli/config.rb +68 -15
- data/lib/cliqr/cli/config_validator.rb +104 -0
- data/lib/cliqr/cli/executor.rb +48 -0
- data/lib/cliqr/cli/interface.rb +50 -13
- data/lib/cliqr/cli/parser/argument_parser.rb +23 -0
- data/lib/cliqr/cli/parser/argument_tree_walker.rb +56 -0
- data/lib/cliqr/cli/parser/option_token.rb +72 -0
- data/lib/cliqr/cli/parser/parsed_argument_builder.rb +66 -0
- data/lib/cliqr/cli/parser/token.rb +38 -0
- data/lib/cliqr/cli/parser/token_factory.rb +58 -0
- data/lib/cliqr/cli/router.rb +24 -0
- data/lib/cliqr/error.rb +49 -5
- data/lib/cliqr/version.rb +1 -1
- data/spec/config/config_validator_spec.rb +21 -6
- data/spec/dsl/interface_spec.rb +137 -1
- data/spec/executor/command_runner_spec.rb +2 -4
- data/spec/executor/executor_spec.rb +85 -0
- data/spec/{executor/fixtures → fixtures}/always_error_command.rb +1 -1
- data/spec/fixtures/option_reader_command.rb +11 -0
- data/spec/{executor/fixtures → fixtures}/test_command.rb +1 -1
- data/spec/fixtures/test_option_reader_command.rb +8 -0
- data/spec/parser/argument_parser_spec.rb +100 -0
- metadata +24 -10
- data/lib/cliqr/cli/builder.rb +0 -31
- data/lib/cliqr/cli/validator.rb +0 -31
- data/spec/executor/router_spec.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21be1b361f2ce33096983d813f3a9185018e5ffd
|
4
|
+
data.tar.gz: f6abf3c9cdeddeb784d690b584505f23f350828f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0dfd50fbfeb23536cd14839f249cdc5f857a4562524c0935eb7788750e28c4cb1ec98c105384b77d2fa34ae8de8ec1e3752d39f45350acc9ac195a3d3f7a972
|
7
|
+
data.tar.gz: 7e43a504e6548df5a6525832498715fd96ef291669af4f0b3d5a252bb53a5ffd8d68bfcd35c5c278605345727368d623f48dec4487f9589656313bb5c7be03a8
|
data/CHANGELOG.md
CHANGED
@@ -1,65 +1,223 @@
|
|
1
|
+
Here is a list of all releases with a description of what went in for
|
2
|
+
that release along with features, improvements and bug fixes. Click on a
|
3
|
+
item in this nested table for further details.
|
4
|
+
|
5
|
+
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
|
6
|
+
**Table of Contents**
|
7
|
+
|
8
|
+
- [0.1.0 / 2015-05-29](#010--2015-05-29)
|
9
|
+
- [Features](#features)
|
10
|
+
- [First pass at building ability to parse command line arguments](#first-pass-at-building-ability-to-parse-command-line-arguments)
|
11
|
+
- [Validations of command line arguments](#validations-of-command-line-arguments)
|
12
|
+
- [Minor improvements](#minor-improvements)
|
13
|
+
- [Organize the specs properly](#organize-the-specs-properly)
|
14
|
+
- [Add more description in README](#add-more-description-in-readme)
|
15
|
+
- [Bug-fixes](#bug-fixes)
|
16
|
+
- [0.0.4 / 2015-05-11](#004--2015-05-11)
|
17
|
+
- [Features](#features)
|
18
|
+
- [Documentation coverage](#documentation-coverage)
|
19
|
+
- [Command options](#command-options)
|
20
|
+
- [Command router](#command-router)
|
21
|
+
- [Command usage building](#command-usage-building)
|
22
|
+
- [Minor improvements](#minor-improvements)
|
23
|
+
- [Improve README example](#improve-readme-example)
|
24
|
+
- [Improve README metrics](#improve-readme-metrics)
|
25
|
+
- [Bug fixes](#bug-fixes)
|
26
|
+
- [Minor style fix in rake tasks](#minor-style-fix-in-rake-tasks)
|
27
|
+
- [Make sure specs don't execute twice](#make-sure-specs-dont-execute-twice)
|
28
|
+
- [0.0.3 / 2015-05-08](#003--2015-05-08)
|
29
|
+
- [Features](#features)
|
30
|
+
- [Test coverage 100%](#test-coverage-100)
|
31
|
+
- [Check code style](#check-code-style)
|
32
|
+
- [Minor improvements](#minor-improvements)
|
33
|
+
- [Detect document coverage](#detect-document-coverage)
|
34
|
+
- [Continue to improve README](#continue-to-improve-readme)
|
35
|
+
- [0.0.2 / 2015-05-07](#002--2015-05-07)
|
36
|
+
- [Features](#features)
|
37
|
+
- [Ability to provide name for top level command](#ability-to-provide-name-for-top-level-command)
|
38
|
+
- [New `rake` tasks](#new-rake-tasks)
|
39
|
+
- [Add badges to README](#add-badges-to-readme)
|
40
|
+
- [Enable travis CI, coveralls and code climate](#enable-travis-ci-coveralls-and-code-climate)
|
41
|
+
- [Add usage example to README](#add-usage-example-to-readme)
|
42
|
+
- [Minor Improvements](#minor-improvements)
|
43
|
+
- [Separate DSL methods](#separate-dsl-methods)
|
44
|
+
- [Bug fixes](#bug-fixes)
|
45
|
+
- [fix rake default task](#fix-rake-default-task)
|
46
|
+
- [0.0.1 / 2015-04-29](#001--2015-04-29)
|
47
|
+
- [Features](#features)
|
48
|
+
- [Ability to build and publish a gem](#ability-to-build-and-publish--a-gem)
|
49
|
+
- [`Rake` as build system](#rake-as-build-system)
|
50
|
+
- [Incorporate `RSpec` for unit tests](#incorporate-rspec-for-unit-tests)
|
51
|
+
|
52
|
+
<!-- markdown-toc end -->
|
53
|
+
|
54
|
+
|
55
|
+
0.1.0 / 2015-05-29
|
56
|
+
==================
|
57
|
+
|
58
|
+
Finally! A minor release!
|
59
|
+
|
60
|
+
A strong command line app needs a strong command line argument
|
61
|
+
parser. This release makes that a reality by introducing a powerful
|
62
|
+
generic command line argument parser with some validation capability as
|
63
|
+
well.
|
64
|
+
|
65
|
+
## Features
|
66
|
+
|
67
|
+
### First pass at building ability to parse command line arguments
|
68
|
+
|
69
|
+
`Cliqr` can now parse command line arguments and their values. It can work
|
70
|
+
with both short names and long names for options.
|
71
|
+
|
72
|
+
### Validations of command line arguments
|
73
|
+
|
74
|
+
A basic set of validations have also been implemented:
|
75
|
+
|
76
|
+
- The option must be defined in the command line config
|
77
|
+
- Cannot use the same option twice
|
78
|
+
|
79
|
+
## Minor improvements
|
80
|
+
|
81
|
+
### Organize the specs properly
|
82
|
+
|
83
|
+
Done by moving fixtures in separate location
|
84
|
+
|
85
|
+
### Add more description in README
|
86
|
+
|
87
|
+
Examples of new developments and remove stale text
|
88
|
+
|
89
|
+
## Bug-fixes
|
90
|
+
|
91
|
+
NONE
|
1
92
|
|
2
93
|
0.0.4 / 2015-05-11
|
3
94
|
==================
|
4
95
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
96
|
+
Extend the capability of CLI app framework by adding some support for
|
97
|
+
command options, routing command to a handler and improved usage
|
98
|
+
information.
|
99
|
+
|
100
|
+
## Features
|
101
|
+
|
102
|
+
### Documentation coverage
|
103
|
+
|
104
|
+
`Cliqr`'s document coverage will be mainted at 100%. This is enforced at
|
105
|
+
build step.
|
106
|
+
|
107
|
+
### Command options
|
108
|
+
|
109
|
+
Add support for defining command's options in the configuration of
|
110
|
+
command line interface. This also prints the option in a descriptive
|
111
|
+
manner in the command's usage.
|
112
|
+
|
113
|
+
### Command router
|
114
|
+
|
115
|
+
Add ability to define a command handler and route the invocation of a
|
116
|
+
command to that handler.
|
117
|
+
|
118
|
+
### Command usage building
|
119
|
+
|
120
|
+
A `erb` template is used to build the usage information for a
|
121
|
+
command. This makes it pretty easy to extend and manipulate the usage
|
122
|
+
information.
|
123
|
+
|
124
|
+
|
125
|
+
## Minor improvements
|
126
|
+
|
127
|
+
### Improve README example
|
128
|
+
|
129
|
+
Add information about option handling, command routing and usage
|
130
|
+
building.
|
131
|
+
|
132
|
+
### Improve README metrics
|
133
|
+
|
134
|
+
Add total downloads badge for gem
|
135
|
+
|
136
|
+
## Bug fixes
|
137
|
+
|
138
|
+
### Minor style fix in rake tasks
|
139
|
+
|
140
|
+
### Make sure specs don't execute twice
|
20
141
|
|
21
142
|
0.0.3 / 2015-05-08
|
22
143
|
==================
|
23
144
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
145
|
+
## Features
|
146
|
+
|
147
|
+
### Test coverage 100%
|
148
|
+
|
149
|
+
Used `simplecov` to assert test coverage ot 100%
|
150
|
+
|
151
|
+
### Check code style
|
152
|
+
|
153
|
+
Use `rubocop` to test code style. This also forced a bump in ruby
|
154
|
+
version to 1.9.3 since older versions are not supported by `rubocop`.
|
155
|
+
|
156
|
+
## Minor improvements
|
157
|
+
|
158
|
+
### Detect document coverage
|
159
|
+
|
160
|
+
Add inch CI badge for this.
|
161
|
+
|
162
|
+
### Continue to improve README
|
163
|
+
|
164
|
+
Add a build section
|
33
165
|
|
34
166
|
0.0.2 / 2015-05-07
|
35
167
|
==================
|
36
168
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
169
|
+
Starting to develop a DSL for command line definition in this
|
170
|
+
release. We will also be extending our usage of `rake`. The `README`
|
171
|
+
file should also be kept up to date.
|
172
|
+
|
173
|
+
## Features
|
174
|
+
|
175
|
+
### Ability to provide name for top level command
|
176
|
+
|
177
|
+
This is the beginning of a DSL for interface config definition
|
178
|
+
|
179
|
+
### New `rake` tasks
|
180
|
+
|
181
|
+
Add tasks like: `cleanup`, `rdoc` and `yard`
|
182
|
+
|
183
|
+
### Add badges to README
|
184
|
+
|
185
|
+
Add badges for build and code metrics. Also use shields.io for badge
|
186
|
+
urls
|
187
|
+
|
188
|
+
### Enable travis CI, coveralls and code climate
|
189
|
+
|
190
|
+
More metrics!!
|
191
|
+
|
192
|
+
### Add usage example to README
|
193
|
+
|
194
|
+
Since documentation is good
|
195
|
+
|
196
|
+
## Minor Improvements
|
197
|
+
|
198
|
+
### Separate DSL methods
|
199
|
+
|
200
|
+
DSL methods should be kept separate from non-DSL methods
|
201
|
+
|
202
|
+
## Bug fixes
|
203
|
+
|
204
|
+
### fix rake default task
|
61
205
|
|
62
206
|
0.0.1 / 2015-04-29
|
63
207
|
==================
|
64
208
|
|
65
|
-
|
209
|
+
This is the start of this gem. Don't expect much.
|
210
|
+
|
211
|
+
## Features
|
212
|
+
|
213
|
+
### Ability to build and publish a gem
|
214
|
+
|
215
|
+
A gem named `cliqr` is created
|
216
|
+
|
217
|
+
### `Rake` as build system
|
218
|
+
|
219
|
+
Rake is the choice of many for building and publishing artifacts
|
220
|
+
|
221
|
+
### Incorporate `RSpec` for unit tests
|
222
|
+
|
223
|
+
From this point on, we will use rspec for unit testing
|
data/README.md
CHANGED
@@ -47,8 +47,9 @@ require 'cliqr'
|
|
47
47
|
|
48
48
|
# a custom command handler
|
49
49
|
class MyCommandHandler < Cliqr.command
|
50
|
-
def execute
|
50
|
+
def execute(context)
|
51
51
|
puts 'executing my awesome command'
|
52
|
+
puts "value for option 'test' is '#{context.option('test').value}'"
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -61,6 +62,8 @@ cli = Cliqr.interface do
|
|
61
62
|
short 'a'
|
62
63
|
description 'this is a option'
|
63
64
|
end
|
65
|
+
|
66
|
+
option 'test'
|
64
67
|
end
|
65
68
|
|
66
69
|
puts cli.usage
|
@@ -72,15 +75,12 @@ puts cli.usage
|
|
72
75
|
#> Available options:
|
73
76
|
#>
|
74
77
|
#> --an-option, -a : this is a option
|
78
|
+
#>
|
79
|
+
#> --test
|
75
80
|
|
76
|
-
cli.execute
|
81
|
+
cli.execute %w(--test some-value)
|
77
82
|
#> executing my awesome command
|
78
|
-
|
79
|
-
|
80
|
-
This should print
|
81
|
-
|
82
|
-
```
|
83
|
-
USAGE: my-command
|
83
|
+
#> value for option 'test' is 'some-value'
|
84
84
|
```
|
85
85
|
|
86
86
|
## Installation
|
data/lib/cliqr.rb
CHANGED
@@ -4,7 +4,7 @@ require 'cliqr/version'
|
|
4
4
|
require 'cliqr/error'
|
5
5
|
|
6
6
|
require 'cliqr/cli/config'
|
7
|
-
require 'cliqr/cli/
|
7
|
+
require 'cliqr/cli/interface'
|
8
8
|
require 'cliqr/cli/command'
|
9
9
|
|
10
10
|
# Top level namespace for the Cliqr gem
|
@@ -23,12 +23,12 @@ module Cliqr
|
|
23
23
|
# option
|
24
24
|
# end
|
25
25
|
#
|
26
|
-
# @return [Cliqr::CLI]
|
26
|
+
# @return [Cliqr::CLI::Interface]
|
27
27
|
#
|
28
28
|
# @api public
|
29
29
|
def interface(&block)
|
30
30
|
config = CLI::Config.build(&block)
|
31
|
-
CLI::
|
31
|
+
CLI::Interface.build(config)
|
32
32
|
end
|
33
33
|
|
34
34
|
# All cliqr commands should extend from this. Here is an example:
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Cliqr
|
4
|
+
module CLI
|
5
|
+
# Utiity class to validate input to a command
|
6
|
+
#
|
7
|
+
# @api private
|
8
|
+
class ArgumentValidator
|
9
|
+
# Validate parsed command line arguments
|
10
|
+
#
|
11
|
+
# @param [Hash] args Parsed argument hash
|
12
|
+
#
|
13
|
+
# @return [Hash] Validated argument hash
|
14
|
+
def validate(args)
|
15
|
+
args
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Cliqr
|
4
|
+
# Definition and builder for command context
|
5
|
+
module CLI
|
6
|
+
# Manages things like arguments and input/output for a command
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
class CommandContext
|
10
|
+
# Command name
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
attr_accessor :command
|
14
|
+
|
15
|
+
# Build a instance of command context based on the parsed set of arguments
|
16
|
+
#
|
17
|
+
# @param [Hash] parsed_args A hash of parsed command line arguments
|
18
|
+
#
|
19
|
+
# @return [Cliqr::CLI::CommandContext]
|
20
|
+
def self.build(parsed_args)
|
21
|
+
CommandContextBuilder.new(parsed_args).build
|
22
|
+
end
|
23
|
+
|
24
|
+
# Initialize the command context (called by the CommandContextBuilder)
|
25
|
+
#
|
26
|
+
# @return [Cliqr::CLI::CommandContext]
|
27
|
+
def initialize(command, options)
|
28
|
+
@command = command
|
29
|
+
# make option map from array
|
30
|
+
@options = Hash[*options.collect { |option| [option.name, option] }.flatten]
|
31
|
+
end
|
32
|
+
|
33
|
+
# List of parsed options
|
34
|
+
#
|
35
|
+
# @return [Array<Cliqr::CLI::CommandOption>]
|
36
|
+
def options
|
37
|
+
@options.values
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get a option by name
|
41
|
+
#
|
42
|
+
# @param [String] name Name of the option
|
43
|
+
#
|
44
|
+
# @return [Cliqr::CLI::CommandOption] Instance of CommandOption for option
|
45
|
+
def option(name)
|
46
|
+
@options[name]
|
47
|
+
end
|
48
|
+
|
49
|
+
private :initialize
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Builder for creating a instance of CommandContext from parsed cli arguments
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
class CommandContextBuilder
|
58
|
+
# Initialize builder for CommandContext
|
59
|
+
#
|
60
|
+
# @param [Hash] parsed_args Parsed and validated command line arguments
|
61
|
+
#
|
62
|
+
# @return [Cliqr::CLI::CommandContextBuilder]
|
63
|
+
def initialize(parsed_args)
|
64
|
+
@parsed_args = parsed_args
|
65
|
+
end
|
66
|
+
|
67
|
+
# Build a new instance of CommandContext
|
68
|
+
#
|
69
|
+
# @return [Cliqr::CLI::CommandContext] A newly created CommandContext instance
|
70
|
+
def build
|
71
|
+
CommandContext.new @parsed_args[:command],
|
72
|
+
@parsed_args[:options].map { |args| CommandOption.new(args) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# A holder class for a command line argument's name and value
|
77
|
+
#
|
78
|
+
# @api private
|
79
|
+
class CommandOption
|
80
|
+
# Name of a command line argument option
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
attr_accessor :name
|
84
|
+
|
85
|
+
# Value for the command line argument's option
|
86
|
+
#
|
87
|
+
# @return [Object]
|
88
|
+
attr_accessor :value
|
89
|
+
|
90
|
+
# Create a new command line option instance
|
91
|
+
#
|
92
|
+
# @param [Hash] args Arguments for creating a command line option
|
93
|
+
#
|
94
|
+
# @return [Cliqr::CLI::CommandContext] A new CommandOption object
|
95
|
+
def initialize(args)
|
96
|
+
@name = args[:name]
|
97
|
+
@value = args[:value]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|