app-cli 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.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in app-cli.gemspec
4
+ gemspec
5
+ getopt
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "app-cli/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "app-cli"
7
+ s.version = App::CLI::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["shelling"]
10
+ s.email = ["navyblueshellingford@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{framework for creating CLI tool set}
13
+ s.description = %q{framework for creating CLI tool set}
14
+
15
+ s.rubyforge_project = "app-cli"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,55 @@
1
+ module App
2
+ module CLI
3
+ require "getopt/long"
4
+ # Your code goes here...
5
+ end
6
+ end
7
+
8
+ module Kernel
9
+ def class_defined?(classname)
10
+ eval("defined? #{classname} == \"constant\" && classname.is_a(Class)")
11
+ end
12
+ end
13
+
14
+ class App::CLI::Dispatcher
15
+
16
+ def self.find
17
+ subcmd = ARGV.shift
18
+ subcmd = self.to_s+"::"+subcmd.capitalize
19
+ eval(subcmd) if class_defined?(subcmd)
20
+ end
21
+
22
+ def self.dispatch(*args)
23
+ handler = self.find
24
+ handler = handler.cascading if handler.cascadable
25
+ options = handler.options
26
+ handler.run( Getopt::Long.getopts(*options), args )
27
+ end
28
+
29
+ end
30
+
31
+ class App::CLI::Command
32
+ @@subcommands = []
33
+ @@options = []
34
+
35
+ def self.subcommands
36
+ self.class_variable_defined?(:@@subcommands) ? @@subcommands : []
37
+ end
38
+
39
+ def self.options
40
+ self.class_variable_defined?(:@@options) ? @@options : []
41
+ end
42
+
43
+ def self.cascading
44
+ if subcmd = self.cascadable
45
+ ARGV.shift
46
+ eval(subcmd)
47
+ end
48
+ end
49
+
50
+ def self.cascadable
51
+ self.subcommands.each do |subcmd|
52
+ return ARGV[0].capitalize == subcmd && class_defined?(self.to_s+"::"+subcmd) ? self.to_s+"::"+subcmd : nil
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module App
2
+ module CLI
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: app-cli
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - shelling
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-07 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: framework for creating CLI tool set
23
+ email:
24
+ - navyblueshellingford@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - app-cli.gemspec
36
+ - lib/app-cli.rb
37
+ - lib/app-cli/version.rb
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: app-cli
68
+ rubygems_version: 1.3.7
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: framework for creating CLI tool set
72
+ test_files: []
73
+