cp 0.0.2 → 0.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,55 +1,12 @@
1
- CP
2
- ==
3
-
4
- Write complex command line scripts simply.
5
-
6
- CP provides an API to write command line scripts with nested subcommands
7
- and switches.
8
-
9
- Rather than reinventing the wheel, CP calls on the time tested [CmdParse][] gem
10
- to do the heavy lifting, wrapping it in an updated API and adding a handful of
11
- new features.
12
-
13
- Roadmap
14
- -------
15
-
16
- CP aims to provide:
17
-
18
- * Automatic help generation
19
- * Any number of nested subcommands
20
- * Global and command-specific switches
21
-
22
- Credit
23
- ------
24
-
25
- CP's API was inspired by the Commander gem.
26
-
27
- I decided I didn't personally like parts
28
- of the Commander API. I forked Commander and began adding features, but found
29
- it difficult to extend, and started work on CP instead.
30
-
31
- [CmdParse]: http://cmdparse.rubyforge.org/
32
-
33
1
  License
34
- -------
2
+ =======
35
3
 
36
4
  (The MIT License)
37
5
 
38
6
  Copyright © 2011 Rick Fletcher <fletch@pobox.com>
39
7
 
40
- Permission is hereby granted, free of charge, to any person obtaining a copy of
41
- this software and associated documentation files (the "Software"), to deal in
42
- the Software without restriction, including without limitation the rights to
43
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
44
- the Software, and to permit persons to whom the Software is furnished to do so,
45
- subject to the following conditions:
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
46
9
 
47
- The above copyright notice and this permission notice shall be included in all
48
- copies or substantial portions of the Software.
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
11
 
50
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
52
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
53
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
54
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
55
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/cp.gemspec CHANGED
@@ -19,4 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency "cmdparse", "~> 2.0.2"
20
20
  s.add_runtime_dependency "highline", "~> 1.6.2"
21
21
  s.add_runtime_dependency "json_pure", "~> 1.5.1"
22
+ s.add_runtime_dependency "terminal-table", "~> 1.4.2"
22
23
  end
@@ -47,6 +47,7 @@ module CP
47
47
  end
48
48
 
49
49
  def run( *args )
50
+ args = ARGV if args.empty?
50
51
  CP::App.instance.runner.new( CP::App.instance ).run( *args )
51
52
  end
52
53
 
@@ -53,7 +53,6 @@ module CP
53
53
  options = ancestors.reverse.inject( {} ) do |o, command|
54
54
  o.merge( command.options )
55
55
  end
56
-
57
56
  validate_options( options )
58
57
 
59
58
  struct = CP::OptionsStruct.new( *options.keys )
@@ -2,8 +2,8 @@ require "optparse"
2
2
 
3
3
  module CP
4
4
  class Option
5
- attr_accessor :allowed, :default, :description, :type
6
- attr_reader :arg, :short, :long
5
+ attr_accessor :allowed, :description, :type
6
+ attr_reader :arg, :default, :short, :long
7
7
 
8
8
  # see: OptionsParser#make_switch
9
9
  def initialize( *args )
@@ -37,6 +37,11 @@ module CP
37
37
  action( &block )
38
38
  end
39
39
 
40
+ def default=( val )
41
+ @default = val
42
+ action.call( val )
43
+ end
44
+
40
45
  def long=( val )
41
46
  set_switch( :long, val )
42
47
  end
@@ -9,11 +9,10 @@ module CP
9
9
  end
10
10
 
11
11
  def run( *args )
12
- args = args.empty? ? args : [args]
13
12
  command_name = ''
14
13
 
15
14
  begin
16
- runner.parse( *args ) { |l, c| command_name << "#{c} " if l > 0 }
15
+ runner.parse( args ) { |l, c| command_name << "#{c} " if l > 0 }
17
16
 
18
17
  rescue ::CmdParse::InvalidCommandError => e
19
18
  command_name << e.message.gsub( /^.*: /, '' )
@@ -1,3 +1,3 @@
1
1
  module CP
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.2.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cp
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rick Fletcher
@@ -45,6 +45,17 @@ dependencies:
45
45
  version: 1.5.1
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: terminal-table
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.4.2
57
+ type: :runtime
58
+ version_requirements: *id004
48
59
  description: An alternative API for CmdParse
49
60
  email:
50
61
  - fletch@pobox.com