rclid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.buildpath +5 -0
- data/.project +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +9 -0
- data/lib/rclid.rb +2 -0
- data/lib/rclid/base.rb +138 -0
- data/lib/rclid/composite.rb +74 -0
- data/lib/rclid/helper/string.rb +75 -0
- data/lib/rclid/version.rb +3 -0
- data/rclid.gemspec +33 -0
- data/samples/base/hello_world.rb +13 -0
- data/samples/composite/hello/hello.rb +7 -0
- data/samples/composite/hello/root.rb +44 -0
- data/samples/composite/hello/world.rb +9 -0
- data/test/lib/rclid/helper/test_string.rb +91 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2JkMTk5NGFmMzk1ODRlOWE1YjNhY2U0MzE4MGRmYmFhOTY2MWZkMw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmEwOTc3YTZjZDhhZWEyMTVhYmVmZjQ3OGY4ZTkyYzdhMGM3ZjRhOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjczYjJmZTBhZTk1M2FmN2JlMmI0MTliYWE3ZjE1YmMzYjU4NTkzOWRiYjk2
|
10
|
+
OTA3NGZmOTljOTFlMjZjNmNlODY2YjI1MDU2NjUxMDkzZmNkYzNmZTVjYjJk
|
11
|
+
OWMwY2ViZTZiZjA5NzJhMTU1ZWU5M2QxOGI0MTI2MTI4MWY1NjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTg0ZDUwNWM4OGFlNGMxNTM3NGM0YmQxZWU1Y2I5MTA4YTQ1MWJiZWY0OTg2
|
14
|
+
MzdiNzBlYjJhNmQ0NGYxOTNmMmU2ZWFhODJiMDgzODk2ZGM0Y2RjZjJjMGNl
|
15
|
+
Njc0ODRjZDg3ODhlNmNkMWQ2MGRhMWRiODk2ODU0YTEyN2UxMDc=
|
data/.buildpath
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>rclid</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matthieu Vachon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Rclid
|
2
|
+
|
3
|
+
The name **Rclid** stands for **Rapid Command Line Interface Development** and
|
4
|
+
is pronounced the way you like.
|
5
|
+
|
6
|
+
As its name implies, the goal of this gem is to provide you with a light
|
7
|
+
structure to create command line interfaces like a breeze.
|
8
|
+
|
9
|
+
Focusing on rapid development, creating basic single command line application
|
10
|
+
or a more complex one using composite sub commands is achieve in light speed.
|
11
|
+
|
12
|
+
If you have ideas that would reduce even more development time and could
|
13
|
+
be that this library, come discuss it with me by creating an issue on
|
14
|
+
github.com.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Install it via [rubygems](https://rubygems.org/gems/rclid)
|
19
|
+
|
20
|
+
$ gem install rclid
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
**Rclid** is really to get started with. The simplest command line
|
25
|
+
application is like the following (file `hello`):
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
#!/usr/bin/env
|
29
|
+
require 'rclid/base'
|
30
|
+
|
31
|
+
class Hello < Rclid::Base
|
32
|
+
def execute()
|
33
|
+
puts "Hello, World!"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
Hello.new().run()
|
38
|
+
```
|
39
|
+
|
40
|
+
This will create a command line application that will print `Hello, World!`
|
41
|
+
in the console when `hello` is called.
|
42
|
+
|
43
|
+
Until I improve this section, there is different locations where
|
44
|
+
you can check for samples that use **Rclid**
|
45
|
+
|
46
|
+
* The samples directory contains some samples ruby files that
|
47
|
+
use **Rclid**. They are commented at different locations to
|
48
|
+
explain the features that you can use.
|
49
|
+
|
50
|
+
* [Buildozer](https://github.com/maoueh/buildozer) is using **Rclid** for its
|
51
|
+
command line interface. Check
|
52
|
+
[here](https://github.com/maoueh/buildozer/blob/master/lib/buildozer/cli/root.rb).
|
53
|
+
|
54
|
+
* [Clivers](https://github.com/maoueh/clivers) is using **Rclid** for its
|
55
|
+
command line interface. Check
|
56
|
+
[here](https://github.com/maoueh/clivers/blob/master/lib/clivers/cli/root.rb).
|
57
|
+
|
58
|
+
* My [personal bin](https://github.com/maoueh/personalbin) is on github. I use **Rclid**
|
59
|
+
for each command I create.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
|
65
|
+
2. Create either a fix branch or a feature branch
|
66
|
+
* `git checkout -b fix-(name-here)`
|
67
|
+
* `git checkout -b feature-(name-here)`
|
68
|
+
|
69
|
+
3. Commit your changes
|
70
|
+
* `git commit -am 'Message describing the fix or feature'`
|
71
|
+
|
72
|
+
4. Push the branch into your repo
|
73
|
+
* `git push origin feature-(name-here)`
|
74
|
+
|
75
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/rclid.rb
ADDED
data/lib/rclid/base.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'rclid/helper/string'
|
4
|
+
|
5
|
+
module Rclid
|
6
|
+
class Base
|
7
|
+
@@MAX_WIDTH = 70
|
8
|
+
|
9
|
+
def initialize(arguments = ARGV, options = {})
|
10
|
+
@arguments = arguments
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Specify the name of the command. Used as the default
|
15
|
+
# name when usage is not defined. So with this, it is
|
16
|
+
# possible to just specify a command name and then
|
17
|
+
# let base class handles the rest.
|
18
|
+
def name()
|
19
|
+
self.class.name.split("::").last().downcase()
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Specify the description of this command.
|
24
|
+
# Overriding classes just need to return a
|
25
|
+
# string that will be output to terminal
|
26
|
+
# as-is. No formatting occurs.
|
27
|
+
def usage()
|
28
|
+
"Usage: #{name()} (options)"
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Specify the description of this command.
|
33
|
+
# Overriding classes just need to return a
|
34
|
+
# string that will be formatted correctly
|
35
|
+
# for the terminal.
|
36
|
+
#
|
37
|
+
# Return nil if you dont want a description,
|
38
|
+
# this is the default.
|
39
|
+
def description()
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Specify the tail of this command.
|
45
|
+
# Overriding classes just need to return a
|
46
|
+
# string that will be formatted correctly
|
47
|
+
# for the terminal.
|
48
|
+
def tail()
|
49
|
+
"Available options:"
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Specify additional arguments parse options
|
54
|
+
# Use OptoinParser syntax
|
55
|
+
def options(parser)
|
56
|
+
parser.on_tail("-h", "--help", "Show help") do
|
57
|
+
help()
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# This is the method that will be invoked to
|
63
|
+
# execute the cli command task.
|
64
|
+
def execute()
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Show command help for this instance and exit
|
69
|
+
# with code 0.
|
70
|
+
def help()
|
71
|
+
puts @parser
|
72
|
+
exit(0)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Print an error message followed by the parser
|
77
|
+
# help.
|
78
|
+
def error(message)
|
79
|
+
puts "ERROR: #{message}"
|
80
|
+
puts ""
|
81
|
+
|
82
|
+
help()
|
83
|
+
end
|
84
|
+
|
85
|
+
def run()
|
86
|
+
@parser = parser()
|
87
|
+
@arguments = parser.parse(@arguments)
|
88
|
+
|
89
|
+
execute()
|
90
|
+
end
|
91
|
+
|
92
|
+
def parser()
|
93
|
+
return @parser if @parser
|
94
|
+
|
95
|
+
parser = OptionParser.new()
|
96
|
+
|
97
|
+
set_usage(parser)
|
98
|
+
set_description(parser)
|
99
|
+
|
100
|
+
options(parser)
|
101
|
+
|
102
|
+
set_tail(parser)
|
103
|
+
parser
|
104
|
+
end
|
105
|
+
|
106
|
+
def set_usage(parser)
|
107
|
+
parser.banner = usage()
|
108
|
+
end
|
109
|
+
|
110
|
+
def set_description(parser)
|
111
|
+
set_text(description(), parser,
|
112
|
+
:prepend_newline => true,
|
113
|
+
:max_width => @@MAX_WIDTH
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def set_tail(parser)
|
118
|
+
set_text(tail(), parser,
|
119
|
+
:prepend_newline => true,
|
120
|
+
:max_width => @@MAX_WIDTH
|
121
|
+
)
|
122
|
+
end
|
123
|
+
|
124
|
+
def set_text(text, parser, options = {})
|
125
|
+
return if not text
|
126
|
+
|
127
|
+
parser.separator("") if options[:prepend_newline]
|
128
|
+
|
129
|
+
lines = text
|
130
|
+
lines = Helper::String::format_text(text, :max_width => options[:max_width]) if not lines.kind_of?(Array)
|
131
|
+
lines.each do |line|
|
132
|
+
parser.separator(line)
|
133
|
+
end
|
134
|
+
|
135
|
+
parser.separator("") if options[:append_newline]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rclid/base'
|
2
|
+
|
3
|
+
module Rclid
|
4
|
+
class Composite < Base
|
5
|
+
def initialize(arguments = ARGV)
|
6
|
+
super(arguments)
|
7
|
+
|
8
|
+
@subcommands = subcommands()
|
9
|
+
@arguments, @command, @subarguments = split_arguments(arguments)
|
10
|
+
|
11
|
+
raise "You must provide at least one subcommand in #{self.class}" if !@subcommands || @subcommands.empty?()
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Default implementation of description for composite
|
16
|
+
# commands.
|
17
|
+
def description()
|
18
|
+
lines = ["Available subcommands:", ""]
|
19
|
+
|
20
|
+
@subcommands.keys().sort().each do |key|
|
21
|
+
lines << " #{key}"
|
22
|
+
end
|
23
|
+
|
24
|
+
lines
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Method to be overriden in child classes to specify
|
29
|
+
# the map of subcommands available to the user.
|
30
|
+
#
|
31
|
+
# The key of the map is a symbol reprensenting the
|
32
|
+
# command name and the value is a constant representing
|
33
|
+
# the class to instantiate when the command name is used
|
34
|
+
# by the user.
|
35
|
+
#
|
36
|
+
# For example:
|
37
|
+
# { :build => Namespace::Build, :destroy => Namespace::Destroy }
|
38
|
+
#
|
39
|
+
def subcommands()
|
40
|
+
{}
|
41
|
+
end
|
42
|
+
|
43
|
+
def run()
|
44
|
+
@parser = parser()
|
45
|
+
@arguments = parser.parse(@arguments)
|
46
|
+
|
47
|
+
return help() if not @command
|
48
|
+
|
49
|
+
command_class = @subcommands[@command.to_sym]
|
50
|
+
return error("The command #{@command} does not exist") if not command_class
|
51
|
+
|
52
|
+
command_class.new(@subarguments).run()
|
53
|
+
end
|
54
|
+
|
55
|
+
def split_arguments(arguments)
|
56
|
+
main_arguments = arguments
|
57
|
+
command = nil
|
58
|
+
sub_arguments = []
|
59
|
+
subcommands = @subcommands.map {|key, classname| key.to_s()}
|
60
|
+
|
61
|
+
arguments.each_index do |i|
|
62
|
+
if subcommands.include?(arguments[i])
|
63
|
+
main_arguments = arguments[0, i]
|
64
|
+
command = arguments[i]
|
65
|
+
sub_arguments = arguments[i + 1, arguments.length - i + 1]
|
66
|
+
|
67
|
+
break
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
return [main_arguments, command, sub_arguments]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Rclid
|
2
|
+
module Helper
|
3
|
+
module String
|
4
|
+
def self.camelize(input)
|
5
|
+
return nil if not input
|
6
|
+
|
7
|
+
parts = input.split(/_/).map do |part|
|
8
|
+
part.capitalize()
|
9
|
+
end
|
10
|
+
|
11
|
+
parts.join("")
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.format_text(text, options = {})
|
15
|
+
tokens = tokenize(text)
|
16
|
+
tokens_to_lines(tokens, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tokenize(text)
|
20
|
+
text.scan(/([^\s]+)|(\n\r|\n|\r)|(\s+)/).map do |word, newline, space|
|
21
|
+
case
|
22
|
+
when word
|
23
|
+
{ :text => word, :type => :word }
|
24
|
+
when newline
|
25
|
+
{ :text => newline, :type => :newline }
|
26
|
+
when space && space =~ /^\s*$/
|
27
|
+
{ :text => space, :type => :space }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.tokens_to_lines(tokens, options = {})
|
33
|
+
max_width = options[:max_width] || 80;
|
34
|
+
indentation = options[:indentation] || ""
|
35
|
+
preserve_paragraphs = options[:preserve_paragraphs] == nil ? true : options[:preserve_paragraphs]
|
36
|
+
|
37
|
+
lines = []
|
38
|
+
buffer = indentation
|
39
|
+
|
40
|
+
newline_count = 0
|
41
|
+
tokens.each do |token|
|
42
|
+
type = token[:type]
|
43
|
+
if type == :newline
|
44
|
+
newline_count += 1
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
if preserve_paragraphs and newline_count > 1
|
49
|
+
for i in 1..newline_count
|
50
|
+
lines << normalize_line(buffer)
|
51
|
+
buffer = indentation
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
newline_count = 0;
|
56
|
+
text = type == :space ? " " : token[:text]
|
57
|
+
potential_width = text.length() + buffer.length()
|
58
|
+
if potential_width > max_width
|
59
|
+
lines << normalize_line(buffer)
|
60
|
+
buffer = indentation
|
61
|
+
end
|
62
|
+
|
63
|
+
buffer += text
|
64
|
+
end
|
65
|
+
|
66
|
+
lines << normalize_line(buffer)
|
67
|
+
lines
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.normalize_line(line, options = {})
|
71
|
+
line.strip()
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/rclid.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rclid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rclid"
|
8
|
+
gem.version = Rclid::VERSION
|
9
|
+
gem.authors = ["Matthieu Vachon"]
|
10
|
+
gem.email = ["matthieu.o.vachon@gmail.com"]
|
11
|
+
gem.summary = "Rapid Command Line Interface Development library"
|
12
|
+
gem.description = <<-EOS
|
13
|
+
As its name implies, the goal of this gem is to provide you with a light
|
14
|
+
structure to create command line interfaces like a breeze.
|
15
|
+
|
16
|
+
Focusing on rapid development, creating basic single command line application
|
17
|
+
or a more complex one using composite subcommands is achieve in light speed.
|
18
|
+
|
19
|
+
If you have ideas that would reduce even more development time and could
|
20
|
+
be that this library, come discuss it with me by creating an issue on
|
21
|
+
github.com.
|
22
|
+
EOS
|
23
|
+
|
24
|
+
gem.homepage = "https://github.com/maoueh/rclid"
|
25
|
+
gem.license = "MIT"
|
26
|
+
|
27
|
+
gem.files = `git ls-files`.split($/) - [".gitattributes", ".gitignore"]
|
28
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
29
|
+
gem.require_paths = ["lib"]
|
30
|
+
|
31
|
+
gem.add_development_dependency "bundler", "~> 1.3"
|
32
|
+
gem.add_development_dependency "rake"
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rclid/composite'
|
4
|
+
|
5
|
+
require_relative 'hello'
|
6
|
+
require_relative 'world'
|
7
|
+
|
8
|
+
# You extend Rclid::Composite to create a composite command
|
9
|
+
class Root < Rclid::Composite
|
10
|
+
def name()
|
11
|
+
# Usually, it would be your application name
|
12
|
+
# (like `clivers` or `nugrant` for example).
|
13
|
+
"composite"
|
14
|
+
end
|
15
|
+
|
16
|
+
def subcommands()
|
17
|
+
# Return the hash symbol -> Class that
|
18
|
+
# represents the sub commands that can
|
19
|
+
# be called from this composite. This is
|
20
|
+
# required.
|
21
|
+
{
|
22
|
+
:hello => Hello,
|
23
|
+
:world => World,
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def options(parser)
|
28
|
+
super(parser)
|
29
|
+
parser.on_tail("-v", "--version", "Show version") do
|
30
|
+
version()
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def version()
|
35
|
+
# Usually, it would be your application version
|
36
|
+
puts "Composite #{Rclid::VERSION}"
|
37
|
+
exit(0)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Only the root needs to be run
|
42
|
+
# So this lines must not be added
|
43
|
+
# to the subcommands
|
44
|
+
Root.new().run()
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'rclid/helper/string'
|
4
|
+
|
5
|
+
module Rclid
|
6
|
+
module Helper
|
7
|
+
class TestString < Test::Unit::TestCase
|
8
|
+
def test_camelize()
|
9
|
+
assert_equal(nil, nil)
|
10
|
+
assert_equal("", Helper::String.camelize(""))
|
11
|
+
assert_equal("Simple", Helper::String.camelize("simple"))
|
12
|
+
assert_equal("SimpleComplex", Helper::String.camelize("simple_complex"))
|
13
|
+
assert_equal("SimpleComplex", Helper::String.camelize("simple_complex"))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_tokenize()
|
17
|
+
text = " first second "
|
18
|
+
tokens = Helper::String.tokenize(text)
|
19
|
+
|
20
|
+
assert_equal([
|
21
|
+
{ :text => " ", :type => :space},
|
22
|
+
{ :text => "first", :type => :word},
|
23
|
+
{ :text => " ", :type => :space},
|
24
|
+
{ :text => "second", :type => :word},
|
25
|
+
{ :text => " ", :type => :space}], tokens)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tokenize_with_line_breaks()
|
29
|
+
text = <<-EOC
|
30
|
+
first
|
31
|
+
second
|
32
|
+
third
|
33
|
+
EOC
|
34
|
+
tokens = Helper::String.tokenize(text)
|
35
|
+
|
36
|
+
assert_equal([
|
37
|
+
{:text => " ", :type => :space},
|
38
|
+
{:text => "first", :type => :word},
|
39
|
+
{:text=>"\n", :type=>:newline},
|
40
|
+
{:text => " ", :type => :space},
|
41
|
+
{:text => "second", :type => :word},
|
42
|
+
{:text=>"\n", :type=>:newline},
|
43
|
+
{:text => " ", :type => :space},
|
44
|
+
{:text => "third", :type => :word},
|
45
|
+
{:text=>"\n", :type=>:newline},
|
46
|
+
], tokens)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_format_text_simple()
|
50
|
+
text = <<-EOC
|
51
|
+
Donec ornare consectetur ante non porttitor. Lorem ipsum dolor
|
52
|
+
sit amet, consectetur adipiscing elit. Ut consequat lacinia ero.
|
53
|
+
EOC
|
54
|
+
|
55
|
+
assert_equal([
|
56
|
+
"Donec ornare consectetur ante non",
|
57
|
+
"porttitor. Lorem ipsum dolor sit amet,",
|
58
|
+
"consectetur adipiscing elit. Ut",
|
59
|
+
"consequat lacinia ero."
|
60
|
+
], Helper::String.format_text(text, :max_width => 40))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_format_text_advanced()
|
64
|
+
text = <<-EOC
|
65
|
+
Lorem ipsum dolor sit amet,
|
66
|
+
consectetur adipiscing elit. Nam egestas "feugiat" quam sed vehicula. Integer placerat;
|
67
|
+
|
68
|
+
odio
|
69
|
+
in condimentum pretium. Nullam at porta lacus, non euismod purus.
|
70
|
+
Donec ornare consectetur ante non porttitor. Lorem ipsum dolor
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
sit amet, consectetur adipiscing elit. Ut consequat lacinia ero.
|
75
|
+
EOC
|
76
|
+
|
77
|
+
assert_equal([
|
78
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam egestas \"feugiat\"",
|
79
|
+
"quam sed vehicula. Integer placerat;",
|
80
|
+
"",
|
81
|
+
"odio in condimentum pretium. Nullam at porta lacus, non euismod purus. Donec",
|
82
|
+
"ornare consectetur ante non porttitor. Lorem ipsum dolor",
|
83
|
+
"",
|
84
|
+
"",
|
85
|
+
"",
|
86
|
+
"sit amet, consectetur adipiscing elit. Ut consequat lacinia ero.",
|
87
|
+
], Helper::String.format_text(text, :max_width => 80))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rclid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthieu Vachon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-19 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ! " As its name implies, the goal of this gem is to provide you with
|
42
|
+
a light\n structure to create command line interfaces like a breeze.\n\n Focusing
|
43
|
+
on rapid development, creating basic single command line application\n or a more
|
44
|
+
complex one using composite subcommands is achieve in light speed.\n\n If you
|
45
|
+
have ideas that would reduce even more development time and could\n be that this
|
46
|
+
library, come discuss it with me by creating an issue on\n github.com.\n"
|
47
|
+
email:
|
48
|
+
- matthieu.o.vachon@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .buildpath
|
54
|
+
- .project
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/rclid.rb
|
60
|
+
- lib/rclid/base.rb
|
61
|
+
- lib/rclid/composite.rb
|
62
|
+
- lib/rclid/helper/string.rb
|
63
|
+
- lib/rclid/version.rb
|
64
|
+
- rclid.gemspec
|
65
|
+
- samples/base/hello_world.rb
|
66
|
+
- samples/composite/hello/hello.rb
|
67
|
+
- samples/composite/hello/root.rb
|
68
|
+
- samples/composite/hello/world.rb
|
69
|
+
- test/lib/rclid/helper/test_string.rb
|
70
|
+
homepage: https://github.com/maoueh/rclid
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Rapid Command Line Interface Development library
|
94
|
+
test_files:
|
95
|
+
- test/lib/rclid/helper/test_string.rb
|