commando 0.0.0 → 0.0.1

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.
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ begin
10
10
  gem.email = "geemus@gmail.com"
11
11
  gem.homepage = "http://github.com/geemus/commando"
12
12
  gem.authors = ["Wesley Beary"]
13
- gem.add_development_dependency "shindo", ">= 0"
13
+ gem.add_development_dependency "shindo", ">=0"
14
+ gem.add_dependency 'formatador', ">=0.0.1"
14
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/commando.gemspec CHANGED
@@ -5,21 +5,19 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{commando}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wesley Beary"]
12
- s.date = %q{2009-11-22}
12
+ s.date = %q{2009-12-01}
13
13
  s.description = %q{Tools for command line interfacing}
14
14
  s.email = %q{geemus@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
16
+ "README.rdoc"
18
17
  ]
19
18
  s.files = [
20
19
  ".document",
21
20
  ".gitignore",
22
- "LICENSE",
23
21
  "README.rdoc",
24
22
  "Rakefile",
25
23
  "VERSION",
@@ -40,11 +38,14 @@ Gem::Specification.new do |s|
40
38
 
41
39
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
40
  s.add_development_dependency(%q<shindo>, [">= 0"])
41
+ s.add_runtime_dependency(%q<formatador>, [">= 0.0.1"])
43
42
  else
44
43
  s.add_dependency(%q<shindo>, [">= 0"])
44
+ s.add_dependency(%q<formatador>, [">= 0.0.1"])
45
45
  end
46
46
  else
47
47
  s.add_dependency(%q<shindo>, [">= 0"])
48
+ s.add_dependency(%q<formatador>, [">= 0.0.1"])
48
49
  end
49
50
  end
50
51
 
data/lib/commando.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rubygems'
2
+ require 'formatador'
3
+
1
4
  class Commando
2
5
 
3
6
  def self.commands(&block)
@@ -7,6 +10,7 @@ class Commando
7
10
  def initialize(&block)
8
11
  @commands = []
9
12
  @descriptions = {}
13
+ @formatador = Formatador.new
10
14
  if block_given?
11
15
  instance_eval(&block)
12
16
  end
@@ -30,30 +34,18 @@ class Commando
30
34
  @descriptions[command.join(' ').squeeze(' ')] = description
31
35
  end
32
36
 
33
- def call(*args)
34
- request = args.join(' ').squeeze(' ').strip
37
+ def call(request = ARGV.join(' ').squeeze(' ').strip)
35
38
  for command in @commands
36
39
  if match = command[0].match(request)
37
40
  response = command[1].call(*match.captures)
38
41
  break
39
42
  end
40
43
  end
41
- unless response
42
- response = available_commands
43
- end
44
- display(response)
45
- end
46
-
47
- def available_commands
48
- display("\nAvailable Commands:\n")
49
-
50
- data = []
51
-
52
- for command, description in @descriptions
53
- data << ["/#{command}/", ' - ', "#{description}"]
44
+ if match
45
+ @formatador.display_line(response)
46
+ else
47
+ display_available_commands
54
48
  end
55
-
56
- columns(data)
57
49
  end
58
50
 
59
51
  def columns(data)
@@ -65,21 +57,36 @@ class Commando
65
57
  end
66
58
  end
67
59
 
68
- table = ''
60
+ lines = []
69
61
  data.length.times do |row|
70
- string = ' '
62
+ string = ''
71
63
  data[row].length.times do |column|
72
64
  value = data[row][column]
73
65
  string << "#{value}#{(' ' * (widths[column] - value.length))}"
74
66
  end
75
- table << string << "\n\n"
67
+ lines << string
68
+ lines << ''
76
69
  end
77
70
 
78
- table.chop!
71
+ lines
79
72
  end
80
73
 
81
- def display(string)
82
- print(string << "\n")
74
+ def display_available_commands
75
+ @formatador.display_line('')
76
+ @formatador.display_line("[bold]OPTIONS[/]")
77
+ @formatador.display_line('')
78
+
79
+ data = []
80
+
81
+ for command, description in @descriptions
82
+ data << ["/#{command}/", ' - ', "#{description}"]
83
+ end
84
+
85
+ @formatador.indent do
86
+ for column in columns(data)
87
+ @formatador.display_line(column)
88
+ end
89
+ end
83
90
  end
84
91
 
85
92
  end
@@ -1,8 +1,23 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/tests_helper')
2
+ require_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'commando'))
3
+
4
+ commands = Tempfile.new('commands')
5
+ commands << <<-COMMANDS
6
+ #!/usr/bin/env ruby
7
+ require '#{require_path}'
8
+ commando = Commando.commands do
9
+ command('no_params', 'prints no_params') { "no_params" }
10
+ command(['param', /(\\d*)/], 'echos param') {|param| param.to_s}
11
+ end
12
+ commando.call
13
+ COMMANDS
14
+ commands.close
15
+ File.chmod(0755, commands.path)
2
16
 
3
17
  Shindo.tests("Commando") do
4
- test("fails") do
5
- "hey buddy, you should probably rename this file and start specing for real"
6
- false
18
+ tests("matching commands") do
19
+ test("basics") { `#{commands.path} no_params` == " no_params\n" }
20
+ test("with param") { `#{commands.path} param 23` == " 23\n" }
7
21
  end
22
+ test("no matching commands") { `#{commands.path} undefined`.include?('OPTIONS') }
8
23
  end
@@ -3,3 +3,4 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'commando'
4
4
  require 'rubygems'
5
5
  require 'shindo'
6
+ require 'tempfile'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commando
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Beary
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-22 00:00:00 -08:00
12
+ date: 2009-12-01 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: formatador
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1
34
+ version:
25
35
  description: Tools for command line interfacing
26
36
  email: geemus@gmail.com
27
37
  executables: []
@@ -29,12 +39,10 @@ executables: []
29
39
  extensions: []
30
40
 
31
41
  extra_rdoc_files:
32
- - LICENSE
33
42
  - README.rdoc
34
43
  files:
35
44
  - .document
36
45
  - .gitignore
37
- - LICENSE
38
46
  - README.rdoc
39
47
  - Rakefile
40
48
  - VERSION
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Wesley Beary
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.