hw 1.1.8 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/hw +4 -2
- data/lib/hw.rb +1 -21
- data/lib/hw/actions.rb +42 -38
- data/lib/hw/base.rb +35 -0
- data/lib/hw/packages.rb +51 -38
- data/lib/hw/runner.rb +53 -0
- data/lib/hw/sources.rb +69 -27
- data/lib/hw/version.rb +2 -2
- metadata +6 -6
- data/lib/hw/cli.rb +0 -96
- data/lib/hw/thor.rb +0 -7
data/bin/hw
CHANGED
data/lib/hw.rb
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
require '
|
2
|
-
require 'thor'
|
3
|
-
require 'thor/group'
|
4
|
-
require 'rails'
|
5
|
-
require 'rails/generators/base'
|
6
|
-
|
7
|
-
module HW
|
8
|
-
DEFAULT_SOURCE = "git@github.com:carrot/hw-packages.git" # CLI
|
9
|
-
DIRECTORY = File.expand_path("~/.hw/") # CLI, HW
|
10
|
-
CONFIG_PATH = "#{DIRECTORY}/config" # CLI, Sources
|
11
|
-
SOURCES_PATH = "#{DIRECTORY}/sources/" # CLI, Packages
|
12
|
-
RESERVED_WORDS = %w(help) # Packages
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'hw/core_ext/string'
|
16
|
-
require 'hw/version'
|
17
|
-
require 'hw/actions'
|
18
|
-
require 'hw/thor'
|
19
|
-
require 'hw/sources'
|
20
|
-
require 'hw/packages'
|
21
|
-
require 'hw/cli'
|
1
|
+
require 'hw/base'
|
data/lib/hw/actions.rb
CHANGED
@@ -1,49 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
class HW
|
2
|
+
module Actions
|
3
|
+
extend Thor::Actions
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def warn msg; say_status "warning", msg, :yellow; end
|
5
|
+
def header msg
|
6
|
+
say_status ">>>", "\e[36m#{msg}\e[0m", :cyan
|
7
|
+
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def info msg; say_status "info", msg, :white; end
|
10
|
+
def success msg; say_status "success", msg, :green; end
|
11
|
+
def error msg; say_status "error", msg, :red; end
|
12
|
+
def warn msg; say_status "warning", msg, :yellow; end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
def replace_file(destination, data = nil, config = {}, &block)
|
15
|
+
remove_file(destination)
|
16
|
+
create_file(destination, data, config, block)
|
17
|
+
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
def bundle
|
20
|
+
header "Bundling gems"
|
21
|
+
run "bundle install --quiet"
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
def migrate(options={})
|
25
|
+
header "Migrating the database"
|
26
|
+
env = options[:env] || 'development'
|
27
|
+
rake("db:migrate", env: env, silence: true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def worker filename, data=nil, &block
|
31
|
+
create_file("app/workers/#{filename}", data, verbose: false, &block)
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def rake(command, options={})
|
35
|
+
env = options[:env] || 'development'
|
36
|
+
capture = options[:silence] || false
|
37
|
+
sudo = options[:sudo] ? 'sudo ' : ''
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
#run rake db:create from "./testing"
|
40
|
+
#success
|
41
|
+
run("#{sudo}rake #{command} RAILS_ENV=#{env}", verbose: false, capture: capture)
|
42
|
+
end
|
40
43
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def git(commands={})
|
45
|
+
if commands.is_a?(Symbol)
|
46
|
+
run "git #{commands}"
|
47
|
+
else
|
48
|
+
commands.each do |cmd, options|
|
49
|
+
run "git #{cmd} #{options}"
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
data/lib/hw/base.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'git'
|
2
|
+
require 'thor'
|
3
|
+
require 'thor/group'
|
4
|
+
require 'hw/core_ext/string'
|
5
|
+
|
6
|
+
class HW < Thor
|
7
|
+
autoload :Actions, 'hw/actions'
|
8
|
+
autoload :Sources, 'hw/sources'
|
9
|
+
autoload :Packages, 'hw/packages'
|
10
|
+
|
11
|
+
DEFAULT_SOURCE = "git@github.com:carrot/hw-packages.git"
|
12
|
+
DIRECTORY = File.expand_path("~/.hw/")
|
13
|
+
CONFIG_PATH = "#{DIRECTORY}/config"
|
14
|
+
SOURCES_PATH = "#{DIRECTORY}/sources/"
|
15
|
+
RESERVED_WORDS = %w(help)
|
16
|
+
|
17
|
+
module Base
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def included(base) # :nodoc:
|
21
|
+
base.send :extend, ClassMethods
|
22
|
+
base.send :include, Thor::Actions
|
23
|
+
base.send :include, Thor::Shell
|
24
|
+
base.send :include, Actions
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def reserved?(arg)
|
30
|
+
arg = arg.first if arg.kind_of?(Array)
|
31
|
+
Thor::THOR_RESERVED_WORDS.include?(arg) or Thor::HELP_MAPPINGS.include?(arg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/hw/packages.rb
CHANGED
@@ -1,51 +1,64 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class HW
|
2
|
+
class Packages
|
3
|
+
extend Thor::Actions
|
4
|
+
extend Thor::Shell
|
5
|
+
extend Actions
|
3
6
|
|
4
|
-
|
7
|
+
class << self
|
8
|
+
@@packages = {}
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def add name
|
11
|
+
Sources.all.each do |key, path|
|
12
|
+
full_path = if HW::Sources.local_source?(path)
|
13
|
+
File.join(path, "#{name}.rb")
|
14
|
+
else
|
15
|
+
File.join(SOURCES_PATH, key, "#{name}.rb")
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
@@packages[name] = full_path if File.exists?(full_path)
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
if reserved?(name)
|
22
|
+
puts "'#{name}' is a reserved word and cannot be defined as a package"
|
23
|
+
exit(1)
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
register(name, @@packages[name])
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def register name, file
|
30
|
+
raise LoadError if file.nil? # TODO: Don't use exception handling.
|
31
|
+
require file
|
32
|
+
klass = Packages::const_get(name.to_pkg)
|
33
|
+
Thor.register(klass, name, "#{name} <command>", "")
|
34
|
+
rescue LoadError
|
35
|
+
puts "The package '#{name}' was not found in any of the sources"
|
36
|
+
exit(1)
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
full_path = File.join(HW::SOURCES_PATH, directory, "*.rb")
|
39
|
+
def list
|
40
|
+
header "Listing available packages"
|
37
41
|
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
Sources.all.keys.each do |directory|
|
43
|
+
full_path = File.join(SOURCES_PATH, directory, "*.rb")
|
44
|
+
|
45
|
+
Dir[full_path].each do |file|
|
46
|
+
key = File.basename(file, '.rb')
|
47
|
+
@@packages[key] = file
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@@packages.merge!({ 'system' => nil, 'help' => nil })
|
52
|
+
@@packages.keys.sort
|
41
53
|
end
|
42
|
-
end
|
43
54
|
|
44
|
-
|
45
|
-
|
46
|
-
|
55
|
+
def formatted_list
|
56
|
+
print_in_columns(Packages.list)
|
57
|
+
end
|
47
58
|
|
48
|
-
|
49
|
-
|
59
|
+
def reserved? name
|
60
|
+
RESERVED_WORDS.include?(name.downcase)
|
61
|
+
end
|
62
|
+
end
|
50
63
|
end
|
51
64
|
end
|
data/lib/hw/runner.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'hw/base'
|
2
|
+
|
3
|
+
class HW::Runner < HW
|
4
|
+
include Base
|
5
|
+
|
6
|
+
def self.start(given_args = ARGV, config = {})
|
7
|
+
unless self.is_a_reserved_task?(given_args)
|
8
|
+
name = ARGV.first
|
9
|
+
|
10
|
+
if Packages.reserved?(name)
|
11
|
+
Packages.register(name, "hw/packages/#{name}")
|
12
|
+
else
|
13
|
+
Packages.add(name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
super(given_args, config)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "list", "list available packages"
|
21
|
+
def list
|
22
|
+
Packages.formatted_list
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "add_source <name> <source>", "Add a source to ~/.hw/config"
|
26
|
+
def add_source name, source
|
27
|
+
Sources.add(name, source)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "update", "Update installed packages"
|
31
|
+
method_option :pull, :aliases => "-p", :type => :boolean, :default => "true", :desc => "Pull from remote sources"
|
32
|
+
def update
|
33
|
+
header "Updating hw"
|
34
|
+
Sources.ensure_defaults
|
35
|
+
|
36
|
+
if options["pull"]
|
37
|
+
Sources.fetch
|
38
|
+
else
|
39
|
+
warn "Sources not updated"
|
40
|
+
info "Remove `-p false` to update your sources"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "install", "Update installed packages"
|
45
|
+
method_option :pull, :aliases => "-p", :type => :boolean, :default => "true", :desc => "Pull from remote sources"
|
46
|
+
alias :install :update
|
47
|
+
|
48
|
+
no_tasks do
|
49
|
+
def self.is_a_reserved_task? args
|
50
|
+
ARGV.empty? or reserved?(args) or self.instance_methods(false).include?(args.first.to_sym)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/hw/sources.rb
CHANGED
@@ -1,38 +1,80 @@
|
|
1
|
-
|
1
|
+
class HW
|
2
|
+
class Sources < Thor
|
3
|
+
extend Thor::Actions
|
4
|
+
extend Thor::Shell
|
5
|
+
extend Actions
|
2
6
|
|
3
|
-
|
4
|
-
|
7
|
+
class << self
|
8
|
+
@@sources = {}
|
5
9
|
|
6
|
-
|
7
|
-
|
10
|
+
def all
|
11
|
+
if File.exists? CONFIG_PATH
|
12
|
+
File.readlines(CONFIG_PATH).each do |line|
|
13
|
+
source = line.split("=")
|
14
|
+
path = source[1].strip
|
15
|
+
path = File.expand_path(path) if local_source?(path)
|
16
|
+
@@sources[source[0]] = path
|
17
|
+
end
|
18
|
+
end
|
8
19
|
|
9
|
-
|
10
|
-
if File.exists? HW::CONFIG_PATH
|
11
|
-
File.readlines(HW::CONFIG_PATH).each do |line|
|
12
|
-
source = line.split("=")
|
13
|
-
path = source[1].strip
|
14
|
-
path = File.expand_path(path) if local_source?(path)
|
15
|
-
@@sources[source[0]] = path
|
20
|
+
@@sources
|
16
21
|
end
|
17
|
-
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
def add name, source
|
24
|
+
self.destination_root = "."
|
25
|
+
header "Appending #{name} to #{CONFIG_PATH}"
|
26
|
+
append_file CONFIG_PATH, "#{name}=#{source}\n"
|
27
|
+
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
def ensure_defaults
|
30
|
+
empty_directory DIRECTORY unless File.exists? DIRECTORY
|
31
|
+
empty_directory SOURCES_PATH unless File.exists? SOURCES_PATH
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
33
|
+
unless File.exists? CONFIG_PATH
|
34
|
+
header "Adding default source to #{CONFIG_PATH}"
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
create_file CONFIG_PATH
|
37
|
+
self.class.new.invoke :add_source, ["default", DEFAULT_SOURCE] # self.class.new added else RSpec screws up.
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch
|
42
|
+
self.all.each do |name, url|
|
43
|
+
begin
|
44
|
+
path = "#{SOURCES_PATH}/#{name}"
|
45
|
+
local = self.local_source?(url)
|
46
|
+
|
47
|
+
unless local
|
48
|
+
if File.exists?(path)
|
49
|
+
Git.open(path).pull
|
50
|
+
else
|
51
|
+
Git.clone(url, name, :path => SOURCES_PATH) unless local
|
52
|
+
end
|
53
|
+
end
|
33
54
|
|
34
|
-
|
35
|
-
|
36
|
-
|
55
|
+
if local and !File.exists?(url)
|
56
|
+
error "Local directory '#{url}' not found. Please check your sources at #{CONFIG_PATH}"
|
57
|
+
else
|
58
|
+
success "Successfully pulled updates from #{url} to #{SOURCES_PATH}#{name}"
|
59
|
+
end
|
60
|
+
rescue Git::GitExecuteError => e
|
61
|
+
warn "Nothing was pulled from #{url}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def git_clone
|
67
|
+
# TODO: Clone git repo
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_pull
|
71
|
+
# TODO: Pull changes from git repo
|
72
|
+
end
|
73
|
+
|
74
|
+
def local_source? path
|
75
|
+
git_regex = /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\-\/]+)/
|
76
|
+
(path =~ git_regex).nil?
|
77
|
+
end
|
78
|
+
end
|
37
79
|
end
|
38
80
|
end
|
data/lib/hw/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.9
|
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-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -89,11 +89,11 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- lib/hw/actions.rb
|
92
|
-
- lib/hw/
|
92
|
+
- lib/hw/base.rb
|
93
93
|
- lib/hw/core_ext/string.rb
|
94
94
|
- lib/hw/packages.rb
|
95
|
+
- lib/hw/runner.rb
|
95
96
|
- lib/hw/sources.rb
|
96
|
-
- lib/hw/thor.rb
|
97
97
|
- lib/hw/version.rb
|
98
98
|
- lib/hw.rb
|
99
99
|
- bin/hw
|
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash: -
|
117
|
+
hash: -3696391133987059405
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
segments:
|
125
125
|
- 0
|
126
|
-
hash: -
|
126
|
+
hash: -3696391133987059405
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
129
|
rubygems_version: 1.8.25
|
data/lib/hw/cli.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
module HW
|
2
|
-
class CLI < HW::Thor
|
3
|
-
def self.start(given_args = ARGV, config = {})
|
4
|
-
unless ARGV.empty? or self.instance_methods(false).include?(ARGV.first.to_sym)
|
5
|
-
name = ARGV.first
|
6
|
-
|
7
|
-
if HW::Packages.reserved?(name)
|
8
|
-
HW::Packages.register(name, "hw/packages/#{name}")
|
9
|
-
else
|
10
|
-
HW::Packages.add(name)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
super(given_args, config)
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "list", "list available packages"
|
18
|
-
def list
|
19
|
-
header "Listing available packages"
|
20
|
-
Thor::Shell::Basic.new.print_in_columns(HW::Packages.list)
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "add_source <name> <source>", "Add a source to ~/.hw/config"
|
24
|
-
def add_source name, source
|
25
|
-
header "Appending #{name} to #{CONFIG_PATH}"
|
26
|
-
append_file CONFIG_PATH, "#{name}=#{source}\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "version", "display gem version information"
|
30
|
-
def version
|
31
|
-
dependency = Gem::Dependency.new('hw', Gem::Requirement::default)
|
32
|
-
versions = Gem::SpecFetcher::fetcher.find_matching(dependency, true, false, false).collect do |entry|
|
33
|
-
if tuple = entry.first
|
34
|
-
tuple[1]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
latest = versions.last.to_s
|
39
|
-
|
40
|
-
if latest != VERSION
|
41
|
-
error "Your version is out of date."
|
42
|
-
info "Your Version: #{VERSION}"
|
43
|
-
info "Current Version: #{latest}"
|
44
|
-
else
|
45
|
-
success "Your version is up to date."
|
46
|
-
info "Your Version: #{VERSION}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
desc "update", "Update installed packages"
|
51
|
-
method_option :pull, :aliases => "-p", :type => :boolean, :default => "true", :desc => "Pull from remote sources"
|
52
|
-
def update
|
53
|
-
header "Updating hw"
|
54
|
-
|
55
|
-
# Setup File Structure
|
56
|
-
empty_directory DIRECTORY unless File.exists? DIRECTORY
|
57
|
-
empty_directory SOURCES_PATH unless File.exists? SOURCES_PATH
|
58
|
-
|
59
|
-
unless File.exists? CONFIG_PATH
|
60
|
-
header "Adding default source to #{CONFIG_PATH}"
|
61
|
-
|
62
|
-
create_file CONFIG_PATH
|
63
|
-
self.class.new.invoke :add_source, ["default", DEFAULT_SOURCE] # self.class.new added else RSpec screws up.
|
64
|
-
end
|
65
|
-
|
66
|
-
# Iterate through sources and take appropriate actions. TODO: Refactor.
|
67
|
-
if options["pull"]
|
68
|
-
HW::Sources.all.each do |name, url|
|
69
|
-
begin
|
70
|
-
path = "#{SOURCES_PATH}/#{name}"
|
71
|
-
local = HW::Sources.local_source?(url)
|
72
|
-
|
73
|
-
unless local
|
74
|
-
if File.exists?(path)
|
75
|
-
Git.open(path).pull
|
76
|
-
else
|
77
|
-
Git.clone(url, name, :path => SOURCES_PATH) unless local
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
if local and !File.exists?(url)
|
82
|
-
error "Local directory '#{url}' not found. Please check your sources at #{CONFIG_PATH}"
|
83
|
-
else
|
84
|
-
success "Successfully pulled updates from #{url} to #{SOURCES_PATH}#{name}"
|
85
|
-
end
|
86
|
-
rescue Git::GitExecuteError => e
|
87
|
-
warn "Nothing was pulled from #{url}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
else
|
91
|
-
warn "Sources not updated"
|
92
|
-
info "Remove --pull=false to update your sources"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|