avalanche-cli 0.1.1 → 0.1.2
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/README.md +10 -6
- data/lib/avalanche/cli/application.rb +1 -1
- data/lib/avalanche/cli/command.rb +1 -1
- data/lib/avalanche/cli/version.rb +1 -1
- metadata +2 -5
- data/cli/application.rb +0 -73
- data/cli/command.rb +0 -50
- data/cli/version.rb +0 -3
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
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
64
|
+
|
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.
|
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-
|
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
|
data/cli/application.rb
DELETED
@@ -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
|
data/cli/command.rb
DELETED
@@ -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
|
data/cli/version.rb
DELETED