commands-lite 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afab1688081598840aee3d5bb9868d07975b20c6
4
- data.tar.gz: 6ab92e22ae2bdcf9303c09560d1fc50b0632972c
3
+ metadata.gz: 693a3892801a9f29d308e2bbd6886525d9303b51
4
+ data.tar.gz: acfebd670a7edd788d13be8793e1a1cb555bb399
5
5
  SHA512:
6
- metadata.gz: fcc60f1b92f4d56989ce3d351c7f08c41989edb6c3059c3eb99edd53549c16803c9e121d1a065c460a66703cc54b9cfeff3e749ee1ce9e848076515eedc95980
7
- data.tar.gz: fbc2e50b756ba87c9875ce4110bef7312ab892a95653800511645e7f695145b2eaa866ce88d10527e53635e150986dfa8a3155eec863687cbcb467190784ad30
6
+ metadata.gz: b2f82d4b9e01c7277c354d1d6f574934bede60a868f17c44b2c77a6fa434187a606e3703115347b31f7df2643d8ba1ba8a20461c3e10a9e2931462049e57dfa8
7
+ data.tar.gz: e57c909ce8dd6c7f302023cbd4f981d006f3ce0021c074d974a064637fbec43b7c7766b3f6c55f4c1be1cd2d9c2006276ed9c354d6dde187106c2d9b03794fb0
@@ -3,4 +3,5 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/commands-lite.rb
6
+ lib/commands-lite/base.rb
6
7
  lib/commands-lite/version.rb
@@ -1,3 +1,19 @@
1
+ require 'pp'
2
+ require 'time'
3
+ require 'date' ## e.g. Date.today etc.
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'fileutils' ## e.g. FileUtils.mkdir_p etc.
7
+ require 'optparse'
8
+
9
+
10
+
1
11
  #####################
2
12
  # our own code
3
13
  require 'commands-lite/version' # note: let version always go first
14
+ require 'commands-lite/base'
15
+
16
+
17
+
18
+ # say hello
19
+ puts CommandsLite.banner
@@ -0,0 +1,129 @@
1
+ class Command
2
+
3
+ def self.option_defs
4
+ @option_defs ||= {}
5
+ end
6
+
7
+ def self.option( key, *args )
8
+ option_defs[ key ] = args
9
+ end
10
+
11
+
12
+
13
+ def options
14
+ @options ||= {}
15
+ end
16
+
17
+ def parse!( args )
18
+ ### todo/check - cache option parser!!!! - why? why not?
19
+ OptionParser.new do |parser|
20
+ ## add default banner - overwrite if needed/to customize
21
+ parser.banner = <<TXT
22
+
23
+ Usage: #{name} [OPTIONS] ARGUMENTS
24
+
25
+ TXT
26
+
27
+ self.class.option_defs.each do | key, on_args|
28
+ parser.on( *on_args ) do |value|
29
+ options[ key ] = value
30
+ end
31
+ end
32
+ end.parse!( args )
33
+ end
34
+
35
+
36
+
37
+ def self.run( args=[] )
38
+ command = new
39
+
40
+ puts "--> (#{command.name}) #{args.join('·')}"
41
+
42
+ ## check for options
43
+ command.parse!( args )
44
+
45
+ puts " #{command.options.size} opt(s): #{command.options.pretty_inspect}"
46
+ puts " #{args.size} arg(s):"
47
+ args.each_with_index do |arg,i|
48
+ puts " #{[i]} >#{arg}<"
49
+ end
50
+
51
+
52
+ if args.size > 0
53
+ ## todo/check: check/verify arity of run - why? why not?
54
+ command.call( *args ) ## use run - why? why not?
55
+ else
56
+ command.call
57
+ end
58
+ end
59
+
60
+
61
+ def self.command_name
62
+ ## note: cut-off leading Yorobot:: for now in class name!!!
63
+ ## note: always remove _ for now too!!!
64
+ ## note: do NOT use @@name!!! - one instance variable per class needed!!
65
+ @name ||= self.name.downcase
66
+ .sub( /^yorobot::/, '' ) ## todo/fix: make "exclude" list configure-able why? why not?
67
+ .gsub( /[_-]/, '' )
68
+ @name
69
+ end
70
+
71
+ def name() self.class.command_name; end
72
+
73
+
74
+
75
+
76
+
77
+ def self.inherited( klass )
78
+ # puts klass.class.name #=> Class
79
+ ## auto-register commands for now - why? why not?
80
+ Commands.register( klass )
81
+ end
82
+
83
+ end # class Command
84
+
85
+
86
+ ############################
87
+ # Commands/Commander registry
88
+ class Commands ## todo/check: use Commander/Command{Index,Registry,...} or such - why? why not?
89
+
90
+ def self.commands ## todo/check: change to registry or such - why? why not?
91
+ @@register ||= {}
92
+ end
93
+
94
+ def self.register( klass )
95
+ raise ArgumentError, "class MUST be a Command" unless klass.ancestors.include?( Command )
96
+
97
+ h = commands
98
+ h[ klass.command_name] = klass
99
+ h
100
+ end
101
+
102
+
103
+ def self.run( args=[] )
104
+ command_name = args.shift
105
+
106
+ ## 1) downcase e.g. GithubStats
107
+ ## 2) remove - to _ ## treat them the same e.g. github-stats => github_stats
108
+ command_name = command_name
109
+ .gsub( /[_-]/, '' )
110
+ .downcase
111
+
112
+ command = commands[ command_name ]
113
+ if command.nil?
114
+ puts "!! ERROR: no command definition found for >#{command_name}<; known commands include:"
115
+ pp commands
116
+ exit 1
117
+ end
118
+
119
+ command.run( args )
120
+ end
121
+
122
+ end # class Commands
123
+
124
+
125
+ ###########################
126
+ ## add a alias / alternative name - why? why not
127
+ Commander = Commands
128
+
129
+
@@ -1,5 +1,20 @@
1
1
  module CommandsLite
2
- VERSION='0.0.1'
3
- end
4
2
 
3
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
+ MINOR = 1
5
+ PATCH = 0
6
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
5
7
 
8
+ def self.version
9
+ VERSION
10
+ end
11
+
12
+ def self.banner
13
+ "commands-lite/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
14
+ end
15
+
16
+ def self.root
17
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
18
+ end
19
+
20
+ end # module CommandsLite
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commands-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -59,6 +59,7 @@ files:
59
59
  - README.md
60
60
  - Rakefile
61
61
  - lib/commands-lite.rb
62
+ - lib/commands-lite/base.rb
62
63
  - lib/commands-lite/version.rb
63
64
  homepage: https://github.com/rubycoco/git
64
65
  licenses: