rubtools 0.0.2 → 0.0.3

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: 2b7fde43c5dde119e84ceefbab2765795eed4f8a
4
- data.tar.gz: fc979aeaf170afb7bb7101dc943ed2ef512d4444
3
+ metadata.gz: 757ab083dd3a5fa2b77ee2af9d468da6cd1a09a3
4
+ data.tar.gz: 449d81e9fd91d84a24e9daf7af232eb382642aec
5
5
  SHA512:
6
- metadata.gz: dd22c1882a3faab75cd324556a67382eb8eb7c9cebb071ea83530d6fdefc3d83043a9b4dec63b79f744f8e7c2687661dfa831a02e9236b85944f0bd40d174860
7
- data.tar.gz: 114863bb8a11c38a9b4d05340adb32b816264a89a82e9fba79ce8c4060fac9242b1b29712992a0d1c7ebaf19a92e528a423ee07f3acb7519ceb1d7b445bf376d
6
+ metadata.gz: eb8fc0176d679be081b2cc4de592f15ca8cf13f052f56110a463c308b267d10f34d6991df836352dfc3b6491e1be416d811cc47202b9da96acbc4c4cdf18dad0
7
+ data.tar.gz: e5f720c0771623e33ed74c9fcdd59ac242222a2ee06b3d5a1885d9348d3a1c3de3871e928a66f956f5d3c53d4c94dc8a48c49ba88edbf117318c4fd7abfdecda
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.1
data/README.md CHANGED
@@ -18,7 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- $ rt android:uninstall com.project
21
+ $ rt -L # List available commands
22
+ $ rt --help
22
23
 
23
24
  ## Contributing
24
25
 
@@ -1,24 +1,29 @@
1
- require 'colorize'
1
+ require 'term/ansicolor'
2
2
 
3
3
  module Rubtools
4
4
  class Logger
5
-
6
5
  # Print success string
7
6
  #
8
- def self.success(arg)
9
- puts arg.colorize(:green)
7
+ def self.success arg
8
+ puts Term::ANSIColor.green { arg }
10
9
  end
11
10
 
12
- # Print info string
11
+ # Print verbose string
13
12
  #
14
- def self.info(arg)
13
+ def self.verbose arg
15
14
  puts arg
16
15
  end
17
16
 
17
+ # Print info string
18
+ #
19
+ def self.info arg
20
+ puts Term::ANSIColor.blue arg
21
+ end
22
+
18
23
  # Print error string
19
24
  #
20
- def self.error(arg)
21
- puts arg.colorize(:red)
25
+ def self.error arg
26
+ puts Term::ANSIColor.red { arg }
22
27
  end
23
28
  end
24
29
  end
@@ -1,23 +1,73 @@
1
1
  module Rubtools
2
2
  class Recipe
3
- attr_writer :options
3
+ attr_accessor :options, :config
4
4
 
5
5
  # Exec without output
6
6
  #
7
- def exec_without_output(args)
8
- Logger.success "$ " + args if @options[:verbose]
7
+ def exec_without_output args
8
+ success "$ " + args if @options[:verbose]
9
9
  return `#{args}`
10
10
  end
11
11
 
12
12
  # Exec with output
13
13
  #
14
- def exec(args)
15
- Logger.success "$ " + args if @options[:verbose]
14
+ def exec args
15
+ success "$ " + args if @options[:verbose]
16
16
  output = `#{args}`
17
- Logger.info "> " + output
17
+ verbose "> " + output
18
18
 
19
19
  return output
20
20
  end
21
+
22
+ ## Get operating system name
23
+ #
24
+ def os
25
+ return (
26
+ host_os = RbConfig::CONFIG['host_os']
27
+ case host_os
28
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
29
+ :windows
30
+ when /darwin|mac os/
31
+ :osx
32
+ when /linux/
33
+ :linux
34
+ when /solaris|bsd/
35
+ :unix
36
+ else
37
+ raise "Unknown os: #{host_os.inspect}"
38
+ end
39
+ )
40
+ end
41
+
42
+ ## Helper to symlink
43
+ #
44
+ def symlink source, dest
45
+ FileUtils.symlink source, dest, verbose: true, force: true
46
+ end
47
+
48
+ # Print success arguments
49
+ #
50
+ def success args
51
+ Logger.success args
52
+ end
53
+
54
+ # Print errors arguments
55
+ #
56
+ def error args
57
+ Logger.error args
58
+ end
59
+
60
+ # Print verbose arguments
61
+ #
62
+ def verbose args
63
+ Logger.verbose args
64
+ end
65
+
66
+ # Print info arguments
67
+ #
68
+ def info args
69
+ Logger.info args
70
+ end
21
71
  end
22
72
  end
23
73
 
@@ -1,3 +1,3 @@
1
1
  module Rubtools
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rubtools.rb CHANGED
@@ -1,12 +1,16 @@
1
- require "rubtools/version"
2
- require "rubtools/recipe"
3
- require "rubtools/logger"
1
+ require 'fileutils'
4
2
  require 'optparse'
5
3
  require "debugger"
4
+ require 'yaml'
5
+ require "ostruct"
6
+ require "recursive-open-struct"
7
+ require 'require_all'
8
+
9
+ require_all Dir.glob(File.join(File.dirname(__FILE__), '**', '*.rb'))
6
10
 
7
11
  module Rubtools
8
12
  class Runner
9
- attr_accessor :args, :tool_libs, :options, :tools
13
+ attr_accessor :args, :option_parser, :options, :tools, :config
10
14
 
11
15
  # Initialize the rubtool
12
16
  # - Find all recipes
@@ -18,36 +22,53 @@ module Rubtools
18
22
  @tools = Hash.new
19
23
  @matches = Array.new
20
24
 
21
- @tool_libs = Dir.glob(File.join(File.dirname(__FILE__), 'tools', '**', '*.rb'))
22
- @tool_libs.each {|lib| require lib }
25
+ rubtools_config_path = File.join(Dir.home, '.rubtools.yml')
26
+ config_hash = YAML::load_file(rubtools_config_path) if File.exists? rubtools_config_path
27
+ @config = RecursiveOpenStruct.new config_hash, recurse_over_arrays: true if config_hash
28
+
29
+ if @config
30
+ tool_libs = []
31
+ if @config.recipes && @config.recipes.any?
32
+ for recipes_folder in @config.recipes
33
+ if File.exists?(recipes_folder) && File.directory?(recipes_folder)
34
+ tool_libs << Dir.glob(File.join(recipes_folder, '**', '*.rb'))
35
+ end
36
+ end
37
+ end
38
+
39
+ # Require recipes from paths in the config file
40
+ require_all tool_libs.flatten
41
+ end
23
42
 
24
- option_parser = OptionParser.new do |opts|
43
+ @option_parser = OptionParser.new do |opts|
25
44
  opts.banner = "Usage: rt constant:method [options]"
26
45
 
27
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
28
- @options[:verbose] = v
29
- end
30
-
31
46
  opts.separator ""
32
47
  opts.separator "Common options:"
33
48
 
49
+ opts.on_tail("-L", "--list", "List available commands") do |l|
50
+ @options[:list] = l
51
+ end
52
+
34
53
  opts.on_tail("-h", "--help", "Show help") do
35
- Logger.info opts
54
+ Logger.verbose opts
36
55
  exit
37
56
  end
38
57
 
58
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
59
+ @options[:verbose] = v
60
+ end
61
+
39
62
  opts.on_tail("--version", "Show rubTools version") do
40
- Logger.info Rubtools::VERSION
63
+ Logger.verbose Rubtools::VERSION
41
64
  exit
42
65
  end
43
66
  end
44
67
 
45
68
  begin
46
- option_parser.parse!(args)
47
- raise ArgumentError, "missing arguments" unless @args.any?
48
- rescue OptionParser::InvalidOption, ArgumentError => e
49
- Logger.info e.message
50
- Logger.info option_parser
69
+ @option_parser.parse!(args)
70
+ rescue OptionParser::InvalidOption
71
+ Logger.verbose @option_parser
51
72
  exit
52
73
  end
53
74
  end
@@ -57,52 +78,72 @@ module Rubtools
57
78
  # - Execute the method
58
79
  #
59
80
  def run!
60
- req_const_method = @args.shift.downcase
61
- values = req_const_method.split(/\W/)
62
-
63
- if values.size == 1
64
- req_method = values.flatten[0]
65
- elsif values.size == 2
66
- req_constant = values.flatten[0]
67
- req_method = values.flatten[1]
68
- end
69
-
70
81
  # Searching in tools libraries the method to call
71
82
  for constant in Rubtools::Tools.constants
72
- @tools[constant] = Array.new
83
+ @tools[constant.downcase] = Array.new
84
+
85
+ methods = Array.new
86
+ methods << Rubtools::Tools.const_get(constant).public_instance_methods(false)
87
+ methods << Rubtools::Tools.const_get(constant).protected_instance_methods
88
+
89
+ for method in methods.flatten
90
+ method_hash = Hash.new
91
+ method_hash[method] = Array.new
92
+
93
+ for param in Rubtools::Tools.const_get(constant).instance_method(method).parameters
94
+ method_hash[method] << param.last
95
+ end
73
96
 
74
- for method in Rubtools::Tools.const_get(constant).instance_methods(false)
75
- @tools[constant] << method
97
+ @tools[constant.downcase] << method_hash
76
98
  end
77
99
  end
78
100
 
79
- for constant in @tools.keys
80
- for method in @tools[constant]
81
- if (req_method == method.to_s.downcase && req_constant == constant.to_s.downcase) || req_method == method.to_s.downcase
82
- @matches << [constant, method]
101
+ if @options[:list]
102
+ Logger.verbose "Available commands: \n\n"
103
+ for constant in @tools.keys
104
+ for method_hash in @tools[constant]
105
+ params = "(#{method_hash.first.last.join(", ")})" if method_hash.first.last.any?
106
+ Logger.success "#{constant}:#{method_hash.keys.first}#{params}"
107
+ end
108
+
109
+ if @tools[constant].any? && @tools.keys.last != constant
110
+ Logger.verbose "--------------------------"
83
111
  end
84
112
  end
113
+ exit
85
114
  end
86
115
 
87
- if @matches.any?
88
- constant = @matches.first[0]
89
- method = @matches.first[1]
116
+ begin
117
+ raise ArgumentError, "missing arguments" unless @args.any?
118
+ rescue ArgumentError => e
119
+ Logger.verbose e.message
120
+ Logger.verbose @option_parser
121
+ exit
122
+ end
90
123
 
91
- Logger.info "Calling #{constant}::#{method}..."
124
+ req_const_method = @args.shift.downcase
125
+ values = req_const_method.split(/\W/)
126
+ constant = values.flatten.first.capitalize
127
+ method = values.flatten.last
128
+
129
+ begin
130
+ Logger.verbose "Calling #{constant}::#{method}..."
92
131
  object = Rubtools::Tools.const_get(constant).new
93
132
  object.options = @options
94
-
95
- begin
96
- if @args.any?
97
- object.method(method).call @args
98
- else
99
- object.method(method).call
100
- end
101
- rescue ArgumentError => e
102
- Logger.error "Method '#{method}' takes arguments: " + e.message
133
+ object.config = @config
134
+
135
+ if @args.any?
136
+ object.method(method).call @args
137
+ else
138
+ object.method(method).call
139
+ end
140
+ rescue Interrupt
141
+ Logger.verbose "Interrupted"
142
+ rescue Exception => e
143
+ Logger.error e.message
144
+ for backtrace in e.backtrace
145
+ Logger.error backtrace
103
146
  end
104
- else
105
- Logger.error "No recipe found..."
106
147
  end
107
148
  end
108
149
  end
data/lib/tools/android.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module Rubtools
2
2
  module Tools
3
3
  class Android < Rubtools::Recipe
4
- attr_accessor :adb
5
4
 
6
5
  # Initialize the Android recipe
7
6
  #
@@ -12,23 +11,23 @@ module Rubtools
12
11
  # Puts the list of available devices
13
12
  #
14
13
  def devices
15
- puts get_devices()
14
+ verbose get_devices
16
15
  end
17
16
 
18
17
  # Remove packages
19
18
  #
20
- def remove(package)
21
- uninstall(package)
19
+ def remove package
20
+ uninstall package
22
21
  end
23
22
 
24
23
  # Uninstall packages
25
24
  #
26
- def uninstall(packages)
27
- devices = get_devices()
25
+ def uninstall packages
26
+ devices = get_devices
28
27
 
29
28
  if devices.any?
30
29
  if devices.size > 1
31
- Logger.info "There is more than one device:"
30
+ verbose "There is more than one device:"
32
31
  devices.each_with_index {|device, index| puts "#{index}: #{device}"}
33
32
  print "Choose one: "
34
33
 
@@ -36,7 +35,7 @@ module Rubtools
36
35
  begin
37
36
  device = devices[Integer(answer)]
38
37
  rescue ArgumentError => e
39
- Logger.error "Error: Not a valid option (" + e.message + ")"
38
+ error "Error: Not a valid option (" + e.message + ")"
40
39
  end
41
40
  else
42
41
  device = devices.first
@@ -44,11 +43,11 @@ module Rubtools
44
43
 
45
44
  if device
46
45
  while packages.size > 0 do
47
- exec(@adb + " -s " + device + " uninstall " + packages.pop)
46
+ exec @adb + " -s " + device + " uninstall " + packages.pop
48
47
  end
49
48
  end
50
49
  else
51
- Logger.error "No found devices..."
50
+ error "No found devices..."
52
51
  end
53
52
  end
54
53
 
data/lib/tools/git.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Rubtools
2
+ module Tools
3
+ class Git < Rubtools::Recipe
4
+
5
+ # Initialize the Android recipe
6
+ #
7
+ def initialize
8
+ @git = "git"
9
+ end
10
+
11
+ def clone_all
12
+ puts @config.git.repos
13
+ end
14
+
15
+ def up_all
16
+ puts @config.git.repos
17
+ end
18
+ end
19
+ end
20
+ end
21
+
data/rubtools.gemspec CHANGED
@@ -18,9 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "colorize"
21
+ spec.add_dependency "term-ansicolor", "~> 1.3.0"
22
+ spec.add_dependency "recursive-open-struct", "~> 0.4.5"
23
+ spec.add_dependency "require_all", "~> 1.3.2"
22
24
 
23
25
  spec.add_development_dependency "bundler", "~> 1.3"
24
26
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "debugger"
27
+ spec.add_development_dependency "debugger", "~> 1.6.6"
26
28
  end
metadata CHANGED
@@ -1,71 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre FILSTROFF
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-06 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: colorize
14
+ name: term-ansicolor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: recursive-open-struct
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: require_all
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.2
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - ~>
59
+ - - "~>"
32
60
  - !ruby/object:Gem::Version
33
61
  version: '1.3'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - ~>
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '1.3'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: debugger
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - '>='
87
+ - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '0'
89
+ version: 1.6.6
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - '>='
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '0'
96
+ version: 1.6.6
69
97
  description: rubTools lets you create command line tasks easily
70
98
  email:
71
99
  - pfilstroff@gmail.com
@@ -74,7 +102,8 @@ executables:
74
102
  extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
- - .gitignore
105
+ - ".gitignore"
106
+ - ".ruby-version"
78
107
  - Gemfile
79
108
  - LICENSE.txt
80
109
  - README.md
@@ -85,6 +114,7 @@ files:
85
114
  - lib/rubtools/recipe.rb
86
115
  - lib/rubtools/version.rb
87
116
  - lib/tools/android.rb
117
+ - lib/tools/git.rb
88
118
  - rubtools.gemspec
89
119
  homepage: ''
90
120
  licenses:
@@ -96,17 +126,17 @@ require_paths:
96
126
  - lib
97
127
  required_ruby_version: !ruby/object:Gem::Requirement
98
128
  requirements:
99
- - - '>='
129
+ - - ">="
100
130
  - !ruby/object:Gem::Version
101
131
  version: '0'
102
132
  required_rubygems_version: !ruby/object:Gem::Requirement
103
133
  requirements:
104
- - - '>='
134
+ - - ">="
105
135
  - !ruby/object:Gem::Version
106
136
  version: '0'
107
137
  requirements: []
108
138
  rubyforge_project:
109
- rubygems_version: 2.1.11
139
+ rubygems_version: 2.2.2
110
140
  signing_key:
111
141
  specification_version: 4
112
142
  summary: A commandline tools framework