hw 1.0.0 → 1.1.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.
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # HW
1
+ [![Gem Version](https://badge.fury.io/rb/hw.png)](https://rubygems.org/gems/hw)
2
+ [![Build Status](https://secure.travis-ci.org/carrot/hw.png?branch=master)](http://travis-ci.org/carrot/hw)
3
+ [![Code Climate](https://codeclimate.com/github/carrot/hw.png)](https://codeclimate.com/github/carrot/hw)
2
4
 
3
- TODO: Write a gem description
5
+ # HW (Hemingway)
6
+
7
+ Package manager for miscellaneous tasks.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,27 +22,7 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- $ hw active_admin install
22
- $ hw active_admin resource <model name>
23
- $ hw airbrake install
24
- $ hw devise install # TODO
25
- $ hw devise strategy <facebook | twitter | instagram | github> # TODO
26
- $ hw git commit # TODO
27
- $ hw git gitignore
28
- $ hw git init
29
- $ hw git remote # TODO
30
- $ hw haml convert
31
- $ hw haml install
32
- $ hw memcache install
33
- $ hw memcache session_store
34
- $ hw memcache start
35
- $ hw new_relic install <license key>
36
- $ hw rails new <project name>
37
- $ hw redis install
38
- $ hw resque install
39
- $ hw resque scheduler
40
- $ hw resque worker <name>
41
- $ hw unicorn install
25
+ $ hw system update
42
26
 
43
27
  ## Contributing
44
28
 
data/bin/hw CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.expand_path('../../lib', __FILE__))
3
- require 'hw/cli'
3
+ require 'hw'
4
4
  HW::CLI.start
data/lib/hw.rb CHANGED
@@ -1,4 +1,23 @@
1
- require "hw/version"
1
+ require 'git'
2
+ require 'thor'
3
+ require 'thor/group'
4
+ require 'httparty'
5
+ require 'active_support/all'
6
+ require 'rails/generators/actions'
7
+
8
+ require 'hw/core_ext/string'
9
+ require 'hw/version'
10
+ require 'hw/actions'
11
+ require 'hw/thor'
12
+ require 'hw/sources'
13
+ require 'hw/packages'
14
+ require 'hw/cli'
2
15
 
3
16
  module HW
17
+ DEFAULT_SOURCE = "git@github.com:carrot/hw-packages.git" # CLI
18
+ DIRECTORY = File.expand_path("~/.hw/") # CLI, HW
19
+ CONFIG_PATH = "#{DIRECTORY}/config" # CLI, Sources
20
+ SOURCES_PATH = "#{DIRECTORY}/sources/" # CLI, Packages
21
+ RESERVED_WORDS = %w(help) # Packages
4
22
  end
23
+
@@ -1,31 +1,30 @@
1
- module HW
2
- module Actions
3
- def header msg
4
- say_status ">>>", "\e[36m#{msg}\e[0m", :cyan
5
- end
1
+ module HW::Actions
2
+ def header msg
3
+ say_status ">>>", "\e[36m#{msg}\e[0m", :cyan
4
+ end
6
5
 
7
- def info msg; say_status "info", msg, :white; end
8
- def success msg; say_status "success", msg, :green; end
9
- def error msg; say_status "error", msg, :red; end
10
- def warn msg; say_status "warning", msg, :yellow; end
6
+ def info msg; say_status "info", msg, :white; end
7
+ def success msg; say_status "success", msg, :green; end
8
+ def error msg; say_status "error", msg, :red; end
9
+ def warn msg; say_status "warning", msg, :yellow; end
11
10
 
12
- def replace_file(destination, data = nil, config = {}, &block)
13
- remove_file(destination)
14
- create_file(destination, data, config, block)
15
- end
11
+ def replace_file(destination, data = nil, config = {}, &block)
12
+ remove_file(destination)
13
+ create_file(destination, data, config, block)
14
+ end
16
15
 
17
- def bundle
18
- header "Bundling gems"
19
- run "bundle install --quiet"
20
- end
16
+ def bundle
17
+ header "Bundling gems"
18
+ run "bundle install --quiet"
19
+ end
21
20
 
22
- def migrate env = :development
23
- header "Migrating the database"
24
- rake "db:migrate", :env => env
25
- end
21
+ def migrate env = :development
22
+ header "Migrating the database"
23
+ rake "db:migrate", :env => env
24
+ end
26
25
 
27
- def worker filename, data=nil, &block
28
- create_file("app/workers/#{filename}", data, :verbose => false, &block)
29
- end
26
+ def worker filename, data=nil, &block
27
+ create_file("app/workers/#{filename}", data, :verbose => false, &block)
30
28
  end
31
29
  end
30
+
@@ -1,75 +1,90 @@
1
- require 'pry'
2
- require 'hw/base'
3
-
4
1
  module HW
5
- class Thor < ::Thor
6
- include Thor::Actions
7
- include Rails::Generators::Actions
8
- include HW::Utilities
9
- include HW::Actions
10
- end
11
-
12
2
  class CLI < HW::Thor
13
3
  def self.start(given_args = ARGV, config = {})
14
- packages = Hash.new
4
+ unless ARGV.empty? or self.instance_methods(false).include?(ARGV.first.to_sym)
5
+ name = ARGV.first
15
6
 
16
- if ARGV.empty?
17
- sources.keys.each do |directory|
18
- full_path = File.join(SOURCES_PATH, directory, "*.rb")
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
19
13
 
20
- Dir[full_path].each do |file|
21
- key = File.basename(file, '.rb')
22
- packages[key] = file
23
- end
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 ~/.cbrc"
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]
24
35
  end
36
+ end
25
37
 
26
- packages.merge!({ 'system' => nil, 'help' => nil })
38
+ latest = versions.last.to_s
27
39
 
28
- Thor::Shell::Basic.new.print_in_columns(packages.keys.sort)
40
+ if latest != VERSION
41
+ error "Your version is out of date."
42
+ info "Your Version: #{VERSION}"
43
+ info "Current Version: #{latest}"
29
44
  else
30
- name = ARGV.first
45
+ success "Your version is up to date."
46
+ info "Your Version: #{VERSION}"
47
+ end
48
+ end
31
49
 
32
- if name != 'settings'
33
- if %w(system help).include?(name)
34
- require 'hw/packages/system'
35
- register(HW::Packages::System, "system", "system <command>", "Perform system commands")
36
- else
37
- sources.keys.each do |directory|
38
- full_path = File.join(SOURCES_PATH, directory, "#{name}.rb")
39
- packages[name] = full_path if File.exists?(full_path)
40
- end
50
+ desc "update", "Update installed packages"
51
+ def update
52
+ header "Updating hw"
41
53
 
42
- begin
43
- require packages[name]
44
- rescue TypeError
45
- puts "Package '#{name}' does not exist in any of the sources."
46
- exit(1)
47
- end
54
+ # Setup File Structure
55
+ empty_directory DIRECTORY unless File.exists? DIRECTORY
56
+ empty_directory SOURCES_PATH unless File.exists? SOURCES_PATH
57
+
58
+ unless File.exists? CONFIG_PATH
59
+ header "Adding default source to #{CONFIG_PATH}"
60
+
61
+ create_file CONFIG_PATH
62
+ invoke :add_source, ["default", DEFAULT_SOURCE]
63
+ end
48
64
 
49
- pkg_name = name.to_pkg
65
+ # Iterate through sources and take appropriate actions. TODO: Refactor.
66
+ HW::Sources.all.each do |name, url|
67
+ begin
68
+ path = "#{SOURCES_PATH}/#{name}"
69
+ local = HW::Sources.local_source?(url)
50
70
 
51
- if RESERVED_WORDS.include?(pkg_name.downcase)
52
- raise "#{pkg_name} is a reserved word and cannot be defined as a package"
71
+ unless local
72
+ if File.exists?(path)
73
+ Git.open(path).pull
74
+ else
75
+ Git.clone(url, name, :path => SOURCES_PATH) unless local
53
76
  end
77
+ end
54
78
 
55
- klass = HW::Packages::const_get(pkg_name)
56
- register(klass, name, "#{name} <command>", "")
79
+ if local and !File.exists?(url)
80
+ error "Local directory '#{url}' not found. Please check your sources at #{CONFIG_PATH}"
81
+ else
82
+ success "Successfully pulled updates from #{url} to #{SOURCES_PATH}#{name}"
57
83
  end
84
+ rescue Git::GitExecuteError => e
85
+ warn "Nothing was pulled from #{url}"
58
86
  end
59
87
  end
60
-
61
- super(given_args, config)
62
- end
63
-
64
- desc "settings", "Display cb settings information"
65
- def settings
66
- hidden = %w(ClassMethods)
67
- constants = HW::Utilities.constants.reject { |c| hidden.include?(c) }
68
- rows = Array.new
69
-
70
- constants.each { |constant| rows << [constant, HW::Utilities::const_get(constant)] }
71
-
72
- Thor::Shell::Basic.new.print_table(rows)
73
88
  end
74
89
  end
75
90
  end
@@ -0,0 +1,46 @@
1
+ module HW::Packages
2
+ extend self
3
+
4
+ @@packages = {}
5
+
6
+ def add name
7
+ HW::Sources.all.keys.each do |directory|
8
+ full_path = File.join(SOURCES_PATH, directory, "#{name}.rb")
9
+ @@packages[name] = full_path if File.exists?(full_path)
10
+ end
11
+
12
+ if reserved?(name)
13
+ puts "'#{name}' is a reserved word and cannot be defined as a package"
14
+ exit(1)
15
+ end
16
+
17
+ register(name, @@packages[name])
18
+ end
19
+
20
+ def register name, file
21
+ require file
22
+ klass = HW::Packages::const_get(name.to_pkg)
23
+ Thor.register(klass, name, "#{name} <command>", "")
24
+ rescue LoadError, TypeError
25
+ puts "The package '#{name}' was not found in any of the sources"
26
+ exit(1)
27
+ end
28
+
29
+ def list
30
+ HW::Sources.all.keys.each do |directory|
31
+ full_path = File.join(SOURCES_PATH, directory, "*.rb")
32
+
33
+ Dir[full_path].each do |file|
34
+ key = File.basename(file, '.rb')
35
+ @@packages[key] = file
36
+ end
37
+ end
38
+
39
+ @@packages.merge!({ 'system' => nil, 'help' => nil })
40
+ @@packages.keys.sort
41
+ end
42
+
43
+ def reserved? name
44
+ RESERVED_WORDS.include?(name.downcase)
45
+ end
46
+ end
@@ -0,0 +1,75 @@
1
+ require 'thor/actions'
2
+
3
+ module HW::Sources
4
+ extend self
5
+
6
+ @@sources = {}
7
+ @@default_source = "git@github.com:carrot/hw-packages.git"
8
+
9
+ def all
10
+ if File.exists? CONFIG_PATH
11
+ File.readlines(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
16
+ end
17
+ end
18
+
19
+ @@sources
20
+ end
21
+
22
+ def add
23
+ # TODO: Currently a part of the System package
24
+ end
25
+
26
+ def git_clone
27
+ # TODO: Clone git repo
28
+ end
29
+
30
+ def git_pull
31
+ # TODO: Pull changes from git repo
32
+ end
33
+
34
+ def local_source? path
35
+ git_regex = /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\-\/]+)/
36
+ (path =~ git_regex).nil?
37
+ end
38
+ end
39
+
40
+
41
+
42
+ # module HW::Sources
43
+ # @@sources = {}
44
+ # @@default_source = "git@github.com:carrot/hw-packages.git"
45
+
46
+ # def self.all
47
+ # if File.exists? CONFIG_PATH
48
+ # File.readlines(CONFIG_PATH).each do |line|
49
+ # source = line.split("=")
50
+ # path = source[1].strip
51
+ # path = File.expand_path(path) if self.local_source?(path)
52
+ # @@sources[source[0]] = path
53
+ # end
54
+ # end
55
+
56
+ # @@sources
57
+ # end
58
+
59
+ # def self.add
60
+ # # TODO: Currently a part of the System package
61
+ # end
62
+
63
+ # def self.git_clone
64
+ # # TODO: Clone git repo
65
+ # end
66
+
67
+ # def self.git_pull
68
+ # # TODO: Pull changes from git repo
69
+ # end
70
+
71
+ # def self.local_source? path
72
+ # git_regex = /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\-\/]+)/
73
+ # (path =~ git_regex).nil?
74
+ # end
75
+ # end
@@ -0,0 +1,7 @@
1
+ module HW
2
+ class Thor < ::Thor
3
+ include Thor::Actions
4
+ include Rails::Generators::Actions
5
+ include HW::Actions
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module HW
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.1"
3
3
  end
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.0.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70195226163260 !ruby/object:Gem::Requirement
16
+ requirement: &70239363443520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70195226163260
24
+ version_requirements: *70239363443520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &70195226162660 !ruby/object:Gem::Requirement
27
+ requirement: &70239363459380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '2.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70195226162660
38
+ version_requirements: *70239363459380
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: rails
41
- requirement: &70195226161660 !ruby/object:Gem::Requirement
41
+ requirement: &70239363458700 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *70195226161660
49
+ version_requirements: *70239363458700
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rake
52
- requirement: &70195226160960 !ruby/object:Gem::Requirement
52
+ requirement: &70239363458240 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :runtime
59
59
  prerelease: false
60
- version_requirements: *70195226160960
60
+ version_requirements: *70239363458240
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: httparty
63
- requirement: &70195226160300 !ruby/object:Gem::Requirement
63
+ requirement: &70239363457820 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: '0'
69
69
  type: :runtime
70
70
  prerelease: false
71
- version_requirements: *70195226160300
71
+ version_requirements: *70239363457820
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: pg
74
- requirement: &70195226195620 !ruby/object:Gem::Requirement
74
+ requirement: &70239363457400 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ! '>='
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '0'
80
80
  type: :runtime
81
81
  prerelease: false
82
- version_requirements: *70195226195620
82
+ version_requirements: *70239363457400
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: git
85
- requirement: &70195226193480 !ruby/object:Gem::Requirement
85
+ requirement: &70239363456980 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ! '>='
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: '0'
91
91
  type: :runtime
92
92
  prerelease: false
93
- version_requirements: *70195226193480
93
+ version_requirements: *70239363456980
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: rspec-rails
96
- requirement: &70195226191800 !ruby/object:Gem::Requirement
96
+ requirement: &70239363456560 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ! '>='
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
- version_requirements: *70195226191800
104
+ version_requirements: *70239363456560
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: ruby-prof
107
- requirement: &70195226190740 !ruby/object:Gem::Requirement
107
+ requirement: &70239363456140 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ! '>='
@@ -112,10 +112,10 @@ dependencies:
112
112
  version: '0'
113
113
  type: :development
114
114
  prerelease: false
115
- version_requirements: *70195226190740
115
+ version_requirements: *70239363456140
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: debugger
118
- requirement: &70195226189640 !ruby/object:Gem::Requirement
118
+ requirement: &70239363455720 !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
121
121
  - - ! '>='
@@ -123,10 +123,10 @@ dependencies:
123
123
  version: '0'
124
124
  type: :development
125
125
  prerelease: false
126
- version_requirements: *70195226189640
126
+ version_requirements: *70239363455720
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: ronn
129
- requirement: &70195226188440 !ruby/object:Gem::Requirement
129
+ requirement: &70239363455300 !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
132
132
  - - ! '>='
@@ -134,10 +134,10 @@ dependencies:
134
134
  version: '0'
135
135
  type: :development
136
136
  prerelease: false
137
- version_requirements: *70195226188440
137
+ version_requirements: *70239363455300
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: rspec
140
- requirement: &70195226050180 !ruby/object:Gem::Requirement
140
+ requirement: &70239363454800 !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
143
143
  - - ~>
@@ -145,10 +145,10 @@ dependencies:
145
145
  version: '2.11'
146
146
  type: :development
147
147
  prerelease: false
148
- version_requirements: *70195226050180
148
+ version_requirements: *70239363454800
149
149
  - !ruby/object:Gem::Dependency
150
150
  name: pry
151
- requirement: &70195226049200 !ruby/object:Gem::Requirement
151
+ requirement: &70239363454380 !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
154
154
  - - ! '>='
@@ -156,10 +156,10 @@ dependencies:
156
156
  version: '0'
157
157
  type: :development
158
158
  prerelease: false
159
- version_requirements: *70195226049200
159
+ version_requirements: *70239363454380
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: sqlite3
162
- requirement: &70195226043560 !ruby/object:Gem::Requirement
162
+ requirement: &70239363453920 !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements:
165
165
  - - ! '>='
@@ -167,7 +167,7 @@ dependencies:
167
167
  version: '0'
168
168
  type: :development
169
169
  prerelease: false
170
- version_requirements: *70195226043560
170
+ version_requirements: *70239363453920
171
171
  description: Package manager for random tasks
172
172
  email:
173
173
  - tmilewski@gmail.com
@@ -177,11 +177,11 @@ extensions: []
177
177
  extra_rdoc_files: []
178
178
  files:
179
179
  - lib/hw/actions.rb
180
- - lib/hw/base.rb
181
180
  - lib/hw/cli.rb
182
181
  - lib/hw/core_ext/string.rb
183
- - lib/hw/packages/system.rb
184
- - lib/hw/utilities.rb
182
+ - lib/hw/packages.rb
183
+ - lib/hw/sources.rb
184
+ - lib/hw/thor.rb
185
185
  - lib/hw/version.rb
186
186
  - lib/hw.rb
187
187
  - bin/hw
@@ -1,10 +0,0 @@
1
- require 'git'
2
- require 'thor'
3
- require 'thor/group'
4
- require 'httparty'
5
- require 'active_support/all' #/concerns
6
- require 'rails/generators/actions'
7
-
8
- require 'hw/core_ext/string'
9
- require 'hw/actions'
10
- require 'hw/utilities'
@@ -1,51 +0,0 @@
1
- module HW
2
- module Packages
3
- class System < HW::Thor
4
- desc "update", "Update installed packages"
5
- def update
6
- header "Updating hw"
7
-
8
- # Setup File Structure
9
- empty_directory DIRECTORY unless File.exists? DIRECTORY
10
- empty_directory SOURCES_PATH unless File.exists? SOURCES_PATH
11
-
12
- unless File.exists? CONFIG_PATH
13
- header "Adding default source to #{CONFIG_PATH}"
14
-
15
- create_file CONFIG_PATH
16
- invoke :add_source, ["default", DEFAULT_SOURCE]
17
- end
18
-
19
- # Iterate through sources and take appropriate actions. TODO: Refactor.
20
- Thor.sources.each do |name, url|
21
- begin
22
- path = "#{SOURCES_PATH}/#{name}"
23
- local = Thor.local?(url)
24
-
25
- unless local
26
- if File.exists?(path)
27
- Git.open(path).pull
28
- else
29
- Git.clone(url, name, :path => SOURCES_PATH) unless local
30
- end
31
- end
32
-
33
- if local and !File.exists?(url)
34
- error "Local directory '#{url}' not found. Please check your sources at #{CONFIG_PATH}"
35
- else
36
- success "Successfully pulled updates from #{url} to #{SOURCES_PATH}#{name}"
37
- end
38
- rescue Git::GitExecuteError => e
39
- warn "Nothing was pulled from #{url}"
40
- end
41
- end
42
- end
43
-
44
- desc "add_source <name> <source>", "Add a source to ~/.cbrc"
45
- def add_source name, source
46
- header "Appending #{name} to #{CONFIG_PATH}"
47
- append_file CONFIG_PATH, "#{name}=#{source}\n"
48
- end
49
- end
50
- end
51
- end
@@ -1,41 +0,0 @@
1
- module HW
2
- module Utilities
3
- DEFAULT_SOURCE = "git@github.com:carrot/hw-packages.git"
4
- DIRECTORY = File.expand_path("~/.hw/")
5
- CONFIG_PATH = "#{DIRECTORY}/config"
6
- SOURCES_PATH = "#{DIRECTORY}/sources/"
7
- RESERVED_WORDS = %w(help system)
8
-
9
- def self.included(base) #:nodoc:
10
- base.extend ClassMethods
11
- end
12
-
13
- module ClassMethods
14
- def sources
15
- if File.exists? CONFIG_PATH
16
- sources = Hash.new
17
-
18
- File.readlines(CONFIG_PATH).each do |line|
19
- source = line.split("=")
20
- path = source[1].strip
21
-
22
- if self.local?(path)
23
- path = File.expand_path(path)
24
- end
25
-
26
- sources[source[0]] = path
27
- end
28
-
29
- sources
30
- else
31
- {}
32
- end
33
- end
34
-
35
- def local? path
36
- git_regex = /([A-Za-z0-9]+@|http(|s)\:\/\/)([A-Za-z0-9.]+)(:|\/)([A-Za-z0-9\-\/]+)/
37
- (path =~ git_regex).nil?
38
- end
39
- end
40
- end
41
- end