clive 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,18 @@
1
+ require 'ast_ast'
2
+
1
3
  require 'clive/parser'
4
+ require 'clive/exceptions'
5
+ require 'clive/tokens'
6
+ require 'clive/ext'
7
+
8
+ require 'clive/option'
9
+ require 'clive/command'
10
+ require 'clive/switch'
11
+ require 'clive/flag'
12
+ require 'clive/bool'
13
+
14
+ require 'clive/output'
15
+ require 'clive/formatter'
2
16
 
3
17
  # Clive is a simple dsl for creating command line interfaces
4
18
  #
@@ -34,7 +34,7 @@ module Clive
34
34
  if truth
35
35
  @names << i.to_s
36
36
  else
37
- @names << "no-#{i.to_s}" if i.length > 1
37
+ @names << "no-#{i.to_s}" if i.to_s.length > 1
38
38
  end
39
39
  end
40
40
 
@@ -38,8 +38,8 @@ module Clive
38
38
  else
39
39
  args.each do |i|
40
40
  case i
41
- when Symbol
42
- @names << i.to_s
41
+ when ::Array
42
+ @names = i.map {|i| i.to_s }
43
43
  when String
44
44
  @desc = i
45
45
  end
@@ -160,7 +160,7 @@ module Clive
160
160
  t = commands[command].tokenize(post_command)
161
161
  r << [:command, commands[command], t]
162
162
  end
163
-
163
+
164
164
  r
165
165
  end
166
166
 
@@ -219,7 +219,7 @@ module Clive
219
219
  # and flags
220
220
  #
221
221
  def command(*args, &block)
222
- @commands << Command.new(*args, @current_desc, &block)
222
+ @commands << Command.new(args, @current_desc, &block)
223
223
  @current_desc = ""
224
224
  end
225
225
 
@@ -1,5 +1,3 @@
1
- require 'strscan'
2
-
3
1
  module Clive
4
2
 
5
3
  # The formatter controls formatting of help. It can be configured
@@ -113,23 +111,14 @@ module Clive
113
111
 
114
112
  def parse_format(format, args)
115
113
  if format
116
- @scanner = StringScanner.new(format)
117
- result = []
118
-
119
- # Create object to eval in
114
+ tokens = Lexer.tokenise(format).to_a
120
115
  obj = Obj.new(args)
121
-
122
- until @scanner.eos?
123
- a = scan_block || a = scan_text
124
- result << a
125
- end
126
-
127
116
  r = ""
128
- result.each do |(t, v)|
117
+ tokens.each do |(t,v)|
129
118
  case t
130
- when :block # contains ruby to eval
119
+ when :block
131
120
  r << obj.evaluate(v)
132
- when :text # add this with no adjustment
121
+ when :text
133
122
  r << v
134
123
  end
135
124
  end
@@ -139,42 +128,19 @@ module Clive
139
128
  end
140
129
  end
141
130
 
131
+ class Lexer < Ast::Tokeniser
132
+ rule :text, /%(.)/ do |i|
133
+ i[1]
134
+ end
142
135
 
143
- # @group Scanning
144
- def scan_block
145
- return unless @scanner.scan /\{/
146
-
147
- pos = @scanner.pos
148
- if @scanner.scan_until /\}/
149
- @scanner.pos -= @scanner.matched.size
150
- [:block, @scanner.pre_match[pos..-1]]
151
- end
136
+ rule :block, /\{(.*?)\}/ do |i|
137
+ i[1]
152
138
  end
153
139
 
154
- def scan_text
155
- text = nil
156
-
157
- pos = @scanner.pos
158
- if @scanner.scan_until /(?<=[^\\])\{/
159
- @scanner.pos -= @scanner.matched.size
160
- text = @scanner.pre_match[pos..-1]
161
- end
162
-
163
- if text.nil?
164
- text = @scanner.rest
165
- @scanner.clear
166
- end
167
-
168
- # Remove }s from text
169
- if text[0] == "}"
170
- text = text[1..-1]
171
- end
172
-
173
- text.gsub!(/\\(.)/) {|m| m[1] }
174
-
175
- [:text, text]
140
+ missing do |i|
141
+ Ast::Token.new(:text, i)
176
142
  end
177
- # @endgroup
143
+ end
178
144
 
179
145
  end
180
146
  end
@@ -1,17 +1,3 @@
1
- require 'clive/exceptions'
2
- require 'clive/tokens'
3
- require 'clive/ext'
4
-
5
- require 'clive/option'
6
- require 'clive/command'
7
- require 'clive/switch'
8
- require 'clive/flag'
9
- require 'clive/bool'
10
-
11
- require 'clive/output'
12
- require 'clive/formatter'
13
-
14
-
15
1
  module Clive
16
2
 
17
3
  # A module wrapping the command line parsing of clive. In the future this
@@ -64,19 +64,18 @@ module Clive
64
64
  def tokens
65
65
  t = []
66
66
  self.each do |i|
67
- if i[0..1] == "--"
67
+ case i
68
+ when /\-\-.+/
68
69
  if i.include?('=')
69
70
  a, b = i[2..i.length].split('=')
70
71
  t << [:long, a] << [:word, b]
71
72
  else
72
73
  t << [:long, i[2..i.length]]
73
74
  end
74
-
75
- elsif i[0] == "-"
75
+ when /\-.+/
76
76
  i[1..i.length].split('').each do |j|
77
77
  t << [:short, j]
78
78
  end
79
-
80
79
  else
81
80
  t << [:word, i]
82
81
  end
@@ -1,3 +1,3 @@
1
1
  module Clive
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Clive::Bool do
4
4
 
5
- subject { Clive::Bool.new([:n, :name], "A test", true) {|arg| puts arg } }
6
- let(:falsey) { Clive::Bool.new([:n, :name], "A test", false) {|arg| puts arg } }
5
+ subject { Clive::Bool.new([:n, :name], "A test", true) {|arg| $stdout.puts arg } }
6
+ let(:falsey) { Clive::Bool.new([:n, :name], "A test", false) {|arg| $stdout.puts arg } }
7
7
 
8
8
  describe "#truth" do
9
9
  it "returns the truth" do
@@ -7,7 +7,7 @@ describe Clive::Command do
7
7
  end
8
8
 
9
9
  subject {
10
- Clive::Command.new(:co, :comm, "A command") do
10
+ Clive::Command.new([:co, :comm], "A command") do
11
11
  bool(:boo) {}
12
12
  switch(:swi) {}
13
13
  flag(:fla) {}
@@ -19,7 +19,7 @@ describe Clive::Command do
19
19
 
20
20
  describe "#initialize" do
21
21
  subject {
22
- Clive::Command.new(:com, "A command") do
22
+ Clive::Command.new([:com], "A command") do
23
23
  flag(:test)
24
24
  end
25
25
  }
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Clive::Flag do
4
4
 
5
- subject { Clive::Flag.new([:S, :say], "Say something", ["WORD(S)"]) {|i| puts i } }
5
+ subject { Clive::Flag.new([:S, :say], "Say something", ["WORD(S)"]) {|i| $stdout.puts i } }
6
6
 
7
7
  it_behaves_like "an option"
8
8
 
@@ -14,7 +14,7 @@ describe Clive::Formatter do
14
14
  describe "#evaluate" do
15
15
  it "evaluates code within the object" do
16
16
  $stdout.should_receive(:puts).with(5)
17
- subject.evaluate("puts test")
17
+ subject.evaluate("$stdout.puts test")
18
18
  end
19
19
  end
20
20
  end
@@ -62,7 +62,7 @@ describe Clive::Formatter do
62
62
  Clive::Flag.new([:args], "With args", ["ARG [OPT]"]),
63
63
  Clive::Flag.new([:choose], "With options", [["a", "b", "c"]])
64
64
  ]
65
- command = Clive::Command.new(:command, "A command")
65
+ command = Clive::Command.new([:command], "A command")
66
66
  result = <<EOS
67
67
  head
68
68
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Clive::Option do
4
- subject { Clive::Option.new([:n, :names], "A test option") { puts "hi" } }
4
+ subject { Clive::Option.new([:n, :names], "A test option") { $stdout.puts "hi" } }
5
5
 
6
6
  it_behaves_like "an option"
7
7
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Clive::Switch do
4
- subject { Clive::Switch.new([:n, :names], "A description") { puts "hi" } }
4
+ subject { Clive::Switch.new([:n, :names], "A description") { $stdout.puts "hi" } }
5
5
 
6
6
  it_behaves_like "an option"
7
7
 
@@ -1,7 +1,7 @@
1
- # $: << File.join(File.dirname(__FILE__), '..')
2
- # $: << File.dirname(__FILE__)
3
- require 'duvet'
4
- Duvet.start :filter => 'clive/lib'
1
+ if RUBY_VERSION >= "1.9"
2
+ require 'duvet'
3
+ Duvet.start :filter => 'clive/lib'
4
+ end
5
5
 
6
6
  require 'rspec'
7
7
  require 'clive'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 0
9
- version: 0.7.0
8
+ - 1
9
+ version: 0.7.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Hawxwell
@@ -14,10 +14,24 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-06 00:00:00 +00:00
17
+ date: 2011-01-07 00:00:00 +00:00
18
18
  default_executable:
19
- dependencies: []
20
-
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ast_ast
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 2
31
+ - 1
32
+ version: 0.2.1
33
+ type: :runtime
34
+ version_requirements: *id001
21
35
  description: " Clive provides a DSL for building command line interfaces. It allows \n you to define commands, switches, flags (switches with options) and \n boolean switches, it then parses the input and runs the correct blocks.\n"
22
36
  email: m@hawx.me
23
37
  executables: []