avalanche-cli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,7 +6,7 @@ A small command line interface library for quickly building cli apps.
6
6
 
7
7
  Add this to your Gemfile:
8
8
 
9
- gem 'cli', :git => 'git://github.com/avalanche123/cli.git'
9
+ gem 'avalanche-cli', :git => 'git://github.com/avalanche123/cli.git'
10
10
 
11
11
  Build a single command script:
12
12
 
@@ -15,9 +15,9 @@ Build a single command script:
15
15
  #!/usr/bin/env ruby
16
16
 
17
17
  require 'bundler/setup'
18
- require 'cli'
18
+ require 'avalanche/cli'
19
19
 
20
- cmd = CLI::Command.new('hello [options] NAME', {
20
+ cmd = Avalanche::CLI::Command.new('hello [options] NAME', {
21
21
  :title => ['--title TITLE', String, 'Desired title']
22
22
  }, Proc.new do |opts, args|
23
23
  raise "NAME is required" if args.empty?
@@ -34,9 +34,9 @@ Build a cli application with many subcommands:
34
34
  #!/usr/bin/env ruby
35
35
 
36
36
  require 'bundler/setup'
37
- require 'cli'
37
+ require 'avalanche/cli'
38
38
 
39
- app = CLI::Application.new('app', '0.1.0')
39
+ app = Avalanche::CLI::Application.new('app', '0.1.0')
40
40
 
41
41
  app.command('hello [options] NAME', "Says Hello", {
42
42
  :title => ['--title TITLE', String, 'Desired title']
@@ -57,4 +57,8 @@ Check it:
57
57
 
58
58
  ## License
59
59
 
60
- MIT
60
+ MIT
61
+
62
+
63
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/avalanche123/cli/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
64
+
@@ -52,7 +52,7 @@ module Avalanche
52
52
  rescue Interrupt
53
53
  exit 0
54
54
  rescue => e
55
- @opts.abort(e.message)
55
+ @opts.abort("#{e.class.name}: #{e.message}")
56
56
  end
57
57
 
58
58
  def to_proc
@@ -48,7 +48,7 @@ module Avalanche
48
48
  puts ""
49
49
  end
50
50
 
51
- @opts.abort(e.message)
51
+ @opts.abort("#{e.class.name}: #{e.message}")
52
52
  end
53
53
 
54
54
  def to_proc
@@ -1,5 +1,5 @@
1
1
  module Avalanche
2
2
  module CLI
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avalanche-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-18 00:00:00.000000000 Z
12
+ date: 2013-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -54,9 +54,6 @@ files:
54
54
  - README.md
55
55
  - Rakefile
56
56
  - cli.gemspec
57
- - cli/application.rb
58
- - cli/command.rb
59
- - cli/version.rb
60
57
  - example/app
61
58
  - example/hello
62
59
  - lib/avalanche/cli.rb
@@ -1,73 +0,0 @@
1
- module CLI
2
- class Application
3
- def initialize(name, version)
4
- @name = name
5
- @version = version
6
- @commands = {}
7
- @opts = OptionParser.new
8
-
9
- @opts.program_name = @name
10
-
11
- @opts.banner = "Usage: #{@name} [--version] [--help] command [options] [args]"
12
-
13
- @opts.top.append("", nil, nil)
14
- @opts.top.append("Available #{@name} commands are:", nil, nil)
15
-
16
- @opts.base.append("", nil, nil)
17
- @opts.base.append("Common options:", nil, nil)
18
-
19
- @opts.on_tail("-h", "--help", "Show this message") { print_help }
20
- @opts.on_tail('-v', '--version', "Show version") { print_version }
21
- end
22
-
23
- def command(usage, description, options, handler)
24
- parts = usage.split(" ")
25
- command = parts.shift
26
-
27
- @opts.separator(sprintf(" %-10.10s %s", command, description))
28
-
29
- parts.unshift("#{@name}-#{command}")
30
-
31
- @commands[command] = Command.new(parts.join(" "), options, handler)
32
- end
33
-
34
- def run(argv)
35
- if argv.empty?
36
- print_help
37
- end
38
-
39
- command = @commands[argv.first]
40
-
41
- if command.nil?
42
- @opts.permute!(argv)
43
- print_help
44
- else
45
- argv.shift
46
- command.run(argv)
47
- end
48
- rescue OptionParser::InvalidOption => e
49
- @opts.warn(e.message)
50
- print_help
51
- rescue Interrupt
52
- exit 0
53
- rescue => e
54
- @opts.abort(e.message)
55
- end
56
-
57
- def to_proc
58
- proc { |opts, args| run(args) }
59
- end
60
-
61
- private
62
-
63
- def print_help
64
- puts @opts
65
- exit 1
66
- end
67
-
68
- def print_version
69
- puts "#{@name} #{@version}"
70
- exit 0
71
- end
72
- end
73
- end
@@ -1,50 +0,0 @@
1
- module CLI
2
- class Command
3
- def initialize(usage, options, handler)
4
- parts = usage.split(/\s+/)
5
- @name = parts.shift
6
- usage = parts.join(" ")
7
- @handler = handler.to_proc
8
- @options = {}
9
- @opts = OptionParser.new
10
-
11
- @opts.program_name = @name
12
-
13
- @opts.banner = "Usage: #{@name} #{usage}"
14
-
15
- options.each do |name, opts|
16
- @opts.on(*opts) do |v|
17
- @options[name] = v
18
- end
19
- end
20
-
21
- @opts.base.append("", nil, nil)
22
- @opts.base.append("Additional options:", nil, nil)
23
-
24
- @opts.on_tail("-h", "--help", "Show this message") { print_help }
25
- end
26
-
27
- def run(argv)
28
- $0 = "#{@name} #{argv.join(" ")}"
29
- @handler.call(@options, @opts.permute!(argv))
30
- rescue OptionParser::InvalidOption => e
31
- @opts.warn(e.message)
32
- print_help
33
- rescue Interrupt
34
- exit 0
35
- rescue => e
36
- @opts.abort(e.message)
37
- end
38
-
39
- def to_proc
40
- proc { |opts, args| run(args) }
41
- end
42
-
43
- private
44
-
45
- def print_help
46
- puts @opts
47
- exit 1
48
- end
49
- end
50
- end
@@ -1,3 +0,0 @@
1
- module CLI
2
- VERSION = "0.1.0"
3
- end