nu 0.1.19 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nu +3 -1
- data/lib/nu.rb +1 -4
- data/lib/nu/api.rb +114 -0
- data/lib/nu/app.rb +151 -0
- data/lib/nu/gem_tools.rb +18 -4
- data/lib/nu/lib_tools.rb +19 -12
- data/lib/nu/loader.rb +12 -22
- data/lib/nu/settings.rb +55 -0
- metadata +11 -26
- data/lib/nu/cli.rb +0 -57
- data/lib/nu/config.rb +0 -37
- data/lib/nu/project.rb +0 -74
data/bin/nu
CHANGED
data/lib/nu.rb
CHANGED
data/lib/nu/api.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib_tools.rb")
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/gem_tools.rb")
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/settings.rb")
|
7
|
+
|
8
|
+
module Nu
|
9
|
+
class Api
|
10
|
+
|
11
|
+
def self.out(out)
|
12
|
+
@stdout = out
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.verbose(verbose)
|
16
|
+
@verbose = verbose
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.load_project_settings(settings_file)
|
20
|
+
log "Load Project Settings called: settings_file=#{settings_file}"
|
21
|
+
@settings_file = settings_file
|
22
|
+
@logger = lambda {|msg| log(msg)}
|
23
|
+
@platforms =
|
24
|
+
['net1_0', 'net1_1', 'net2_0', 'net3_0', 'net3_5', 'net4_0',
|
25
|
+
'mono1_0', 'mono2_0',
|
26
|
+
'silverlight_2_0', 'silverlight_3_0', 'silverlight_4_0']
|
27
|
+
|
28
|
+
@project_settings = YAML.load_file(@settings_file) if File.exist?(@settings_file)
|
29
|
+
@project_settings = OpenStruct.new if @project_settings == nil
|
30
|
+
Nu::SettingsExtension.mix_in(@project_settings)
|
31
|
+
|
32
|
+
#set defaults just in case they didn't load
|
33
|
+
@project_settings.lib = OpenStruct.new if @project_settings.lib == nil
|
34
|
+
@project_settings.lib.location = './lib' if @project_settings.lib.location == nil
|
35
|
+
@project_settings.lib.use_long_names = false if @project_settings.lib.use_long_names == nil
|
36
|
+
|
37
|
+
if @verbose
|
38
|
+
disp "Project Settings:"
|
39
|
+
disp YAML.dump(@project_settings).gsub('!ruby/object:OpenStruct','').gsub(/\s*table:/,'').gsub('---','')
|
40
|
+
disp ""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.store_setting(name, value)
|
45
|
+
log "Store Setting called: name=#{name} value=#{value}"
|
46
|
+
log "Before:"
|
47
|
+
load_project_settings(@settings_file) if @verbose
|
48
|
+
|
49
|
+
@project_settings.set_setting_by_path(name, value, @logger)
|
50
|
+
assert_project_settings
|
51
|
+
|
52
|
+
File.open(@settings_file, 'w') do |out|
|
53
|
+
YAML.dump(@project_settings, out)
|
54
|
+
end
|
55
|
+
log "After:"
|
56
|
+
load_project_settings(@settings_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.assert_project_settings
|
60
|
+
if @project_settings.platform
|
61
|
+
@project_settings.platform = @project_settings.platform.gsub('.','_')
|
62
|
+
if !@platforms.index(@project_settings.platform)
|
63
|
+
disp "'#{@project_settings.platform}' is not a valid platform."
|
64
|
+
disp "\nChoose one of these:"
|
65
|
+
@platforms.each {|p| disp " #{p}"}
|
66
|
+
disp ""
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.get_setting(name)
|
73
|
+
log "Get Setting called: name=#{name}"
|
74
|
+
@project_settings.get_setting_by_path(name, @logger)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.version_string
|
78
|
+
nu_spec = Nu::GemTools.spec_for("nu")
|
79
|
+
"Nubular, version #{nu_spec.version}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.install_package(package_name, package_version)
|
83
|
+
log "Install called: package_name=#{package_name} package_version=#{package_version}."
|
84
|
+
|
85
|
+
loader = Nu::Loader.new(package_name, package_version, @project_settings.lib.location, @project_settings.lib.use_long_names)
|
86
|
+
if loader.load_gem
|
87
|
+
loader.copy_to_lib
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.output_report()
|
93
|
+
log "Report called."
|
94
|
+
|
95
|
+
disp "\n"
|
96
|
+
disp "The following packages are installed:"
|
97
|
+
disp "====================================="
|
98
|
+
Nu::LibTools.read_specs_from_lib(@project_settings.lib.location).each{|i| disp " " + i.full_name}
|
99
|
+
disp "====================================="
|
100
|
+
disp ""
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def self.log(msg)
|
106
|
+
disp(msg) if @verbose
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.disp(msg)
|
110
|
+
@stdout << msg + "\n"
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
data/lib/nu/app.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'date'
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/api.rb")
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + "/loader.rb")
|
8
|
+
|
9
|
+
class App
|
10
|
+
|
11
|
+
attr_reader :options
|
12
|
+
|
13
|
+
def initialize(arguments, stdin, stdout)
|
14
|
+
|
15
|
+
#special case, they want to know our version
|
16
|
+
if arguments.count == 1 && arguments[0] == '--version'
|
17
|
+
output_version
|
18
|
+
exit 0
|
19
|
+
end
|
20
|
+
|
21
|
+
Nu::Api.out(stdout)
|
22
|
+
|
23
|
+
@arguments = arguments
|
24
|
+
|
25
|
+
# Set defaults
|
26
|
+
@options = OpenStruct.new
|
27
|
+
@options.verbose = false
|
28
|
+
@options.quiet = false
|
29
|
+
@commands = []
|
30
|
+
|
31
|
+
begin
|
32
|
+
OptionParser.new do |opts|
|
33
|
+
|
34
|
+
opts.banner = ["Usage: nu install PACKAGE [options]",
|
35
|
+
"\nConfig: nu config NAME VALUE",
|
36
|
+
"\nReport: nu report"]
|
37
|
+
|
38
|
+
opts.on('-v', '--version VERSION','Specify version of package to install' ) do |ver|
|
39
|
+
@options.package_version = ver
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-r','--report', 'Report on the packages currently installed in the lib folder') do
|
43
|
+
@commands << lambda {Nu::Api.output_report}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Specify options
|
47
|
+
opts.on('-V', '--verbose') { @options.verbose = true }
|
48
|
+
opts.on('-q', '--quiet') { @options.quiet = true }
|
49
|
+
|
50
|
+
opts.on_tail( '-h', '--help', 'Display this screen' ) do
|
51
|
+
output_help(opts)
|
52
|
+
end
|
53
|
+
|
54
|
+
@help_command = lambda{output_help(opts)}
|
55
|
+
|
56
|
+
end.parse!
|
57
|
+
rescue
|
58
|
+
@help_command.call
|
59
|
+
end
|
60
|
+
|
61
|
+
post_process_options
|
62
|
+
extract_commands
|
63
|
+
end
|
64
|
+
|
65
|
+
def run
|
66
|
+
|
67
|
+
if arguments_valid?
|
68
|
+
|
69
|
+
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
70
|
+
output_version if @options.verbose
|
71
|
+
output_inputs if @options.verbose
|
72
|
+
|
73
|
+
Nu::Api.verbose(@options.verbose)
|
74
|
+
Nu::Api.load_project_settings('nuniverse.yaml')
|
75
|
+
|
76
|
+
@commands.reverse.each {|command| command.call}
|
77
|
+
|
78
|
+
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
79
|
+
|
80
|
+
else
|
81
|
+
@help_command.call
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
def extract_commands
|
89
|
+
if @arguments.count > 0
|
90
|
+
@options.command = @arguments[0].downcase
|
91
|
+
case @options.command
|
92
|
+
when 'report'
|
93
|
+
@commands << lambda {Nu::Api.output_report}
|
94
|
+
when 'install'
|
95
|
+
assert_param_count(2)
|
96
|
+
@options.package = @arguments[1]
|
97
|
+
@commands << lambda {Nu::Api.install_package(@options.package, @options.package_version)}
|
98
|
+
# when 'uninstall'
|
99
|
+
# assert_param_count(2)
|
100
|
+
# @options.package = @arguments[1]
|
101
|
+
# @commands << lambda {Nu::Api.uninstall_package(@options.package, @options.package_version)}
|
102
|
+
when 'config'
|
103
|
+
if @arguments.count == 2
|
104
|
+
@commands << lambda {puts "#{@arguments[1]} = #{Nu::Api.get_setting(@arguments[1])}"}
|
105
|
+
else
|
106
|
+
assert_param_count(3)
|
107
|
+
@commands << lambda do
|
108
|
+
Nu::Api.store_setting(@arguments[1], @arguments[2])
|
109
|
+
puts "#{@arguments[1]} = #{Nu::Api.get_setting(@arguments[1])}"
|
110
|
+
end if @arguments.count == 3
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def assert_param_count(count)
|
117
|
+
unless @arguments.count == count
|
118
|
+
@help_command.call
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def post_process_options
|
123
|
+
@options.verbose = false if !@options.verbose
|
124
|
+
@options.verbose = false if @options.quiet
|
125
|
+
end
|
126
|
+
|
127
|
+
# True if required arguments were provided
|
128
|
+
def arguments_valid?
|
129
|
+
true if @commands.count > 0
|
130
|
+
end
|
131
|
+
|
132
|
+
def output_inputs
|
133
|
+
puts "Inputs:\n"
|
134
|
+
|
135
|
+
@options.marshal_dump.each do |name, val|
|
136
|
+
puts " #{name} = #{val}"
|
137
|
+
end
|
138
|
+
puts ""
|
139
|
+
end
|
140
|
+
|
141
|
+
def output_help(opts)
|
142
|
+
output_version
|
143
|
+
puts opts
|
144
|
+
exit 0
|
145
|
+
end
|
146
|
+
|
147
|
+
def output_version
|
148
|
+
puts Nu::Api.version_string
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
data/lib/nu/gem_tools.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
module Nu
|
4
5
|
class GemTools
|
5
6
|
|
6
|
-
def self.spec_for(
|
7
|
+
def self.spec_for(spec, requirement=nil)
|
7
8
|
unless requirement.respond_to?('satisfied_by?')
|
8
9
|
requirement = Gem::Requirement.create(requirement)
|
9
10
|
end
|
10
|
-
dependency = Gem::Dependency.new(
|
11
|
+
dependency = Gem::Dependency.new(spec,requirement)
|
11
12
|
searcher = Gem::GemPathSearcher.new()
|
12
13
|
all_installed_gems = searcher.init_gemspecs()
|
13
14
|
|
@@ -15,8 +16,8 @@ module Nu
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.lib_for(name, requirement=nil)
|
18
|
-
|
19
|
-
gem_path =
|
19
|
+
spec = spec_for(name, requirement)
|
20
|
+
gem_path = spec.full_gem_path
|
20
21
|
libdir = File.join(gem_path,"lib")
|
21
22
|
unless File.exist?(libdir)
|
22
23
|
libdir = IO.readlines(File.join(gem_path, ".require_paths"))[0].strip
|
@@ -25,5 +26,18 @@ module Nu
|
|
25
26
|
libdir
|
26
27
|
end
|
27
28
|
|
29
|
+
def self.write_spec(spec, dest)
|
30
|
+
dest = File.expand_path(dest)
|
31
|
+
dest = File.join(dest,'nu_spec.yaml')
|
32
|
+
|
33
|
+
unless spec.is_a?(Gem::Specification)
|
34
|
+
spec = spec_for(spec)
|
35
|
+
end
|
36
|
+
|
37
|
+
File.open( dest, 'w' ) do |out|
|
38
|
+
YAML.dump(spec, out)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
end
|
29
43
|
end
|
data/lib/nu/lib_tools.rb
CHANGED
@@ -3,20 +3,27 @@ require 'rubygems'
|
|
3
3
|
module Nu
|
4
4
|
class LibTools
|
5
5
|
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.folder_for(spec, lib, long_name=false)
|
7
|
+
if long_name
|
8
|
+
name = spec.full_name
|
9
|
+
else
|
10
|
+
name = spec.name
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
to = Dir.pwd + "/#{lib}/#{name}"
|
14
|
+
if Dir[to] == [] #may need a smarter guy here
|
15
|
+
FileUtils.mkpath to
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
name = spec.full_name
|
16
|
-
else
|
17
|
-
name = spec.name
|
18
|
-
end
|
19
|
-
Dir.pwd + "/#{lib}/#{name}"
|
18
|
+
return to
|
20
19
|
end
|
20
|
+
|
21
|
+
def self.read_specs_from_lib(lib)
|
22
|
+
lib = File.expand_path(lib)
|
23
|
+
glob = "#{lib}/**/nu_spec.yaml"
|
24
|
+
files = Dir.glob(glob)
|
25
|
+
files.map{|file| YAML::load_file(file)}
|
26
|
+
end
|
27
|
+
|
21
28
|
end
|
22
29
|
end
|
data/lib/nu/loader.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'rubygems/dependency_installer'
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + "/lib_tools.rb")
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + "/gem_tools.rb")
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + "/project.rb")
|
6
5
|
|
7
6
|
module Nu
|
8
7
|
class Loader
|
@@ -11,14 +10,17 @@ module Nu
|
|
11
10
|
attr :location
|
12
11
|
attr :version
|
13
12
|
|
14
|
-
def initialize(name, location,
|
13
|
+
def initialize(name, version, location, long_names)
|
15
14
|
#improve the crap out of this
|
15
|
+
@long_names = long_names
|
16
16
|
@gem_name = name
|
17
17
|
@location = location
|
18
18
|
@version = version
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def load_gem
|
22
|
+
if !gem_available?
|
23
|
+
puts "Gem #{(@gem_name + " #{@version}").strip} is not installed locally - I am now going to try and install it"
|
22
24
|
begin
|
23
25
|
inst = Gem::DependencyInstaller.new
|
24
26
|
inst.install @gem_name, @version
|
@@ -27,13 +29,12 @@ module Nu
|
|
27
29
|
end
|
28
30
|
rescue Gem::GemNotFoundException => e
|
29
31
|
puts "ERROR: #{e.message}"
|
30
|
-
return
|
32
|
+
return false
|
31
33
|
end
|
32
34
|
else
|
33
|
-
|
35
|
+
return true
|
34
36
|
end
|
35
|
-
|
36
|
-
end
|
37
|
+
end
|
37
38
|
|
38
39
|
def copy_to_lib
|
39
40
|
start_here = copy_source
|
@@ -43,6 +44,7 @@ module Nu
|
|
43
44
|
puts "Copy To: #{to}"
|
44
45
|
|
45
46
|
FileUtils.copy_entry start_here, to
|
47
|
+
Nu::GemTools.write_spec(gemspec, to)
|
46
48
|
|
47
49
|
process_dependencies
|
48
50
|
end
|
@@ -64,26 +66,14 @@ module Nu
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def copy_dest
|
67
|
-
|
68
|
-
|
69
|
-
#to be used in copying
|
70
|
-
if proj.should_use_long_names?
|
71
|
-
name = gemspec.full_name
|
72
|
-
else
|
73
|
-
name = gemspec.name
|
74
|
-
end
|
75
|
-
to = Dir.pwd + "/#{@location}/#{name}"
|
76
|
-
if Dir[to] == [] #may need a smarter guy here
|
77
|
-
FileUtils.mkpath to
|
78
|
-
end
|
79
|
-
to
|
69
|
+
Nu::LibTools.folder_for(gemspec, @location, @long_names)
|
80
70
|
end
|
81
71
|
|
82
72
|
def process_dependencies
|
83
73
|
gemspec.dependencies.each do |d|
|
84
74
|
if Gem.available? d.name
|
85
75
|
puts "Loading dependency: #{d.name} #{d.requirement}"
|
86
|
-
loader = Loader.new(d.name, @location,
|
76
|
+
loader = Loader.new(d.name, d.requirement, @location, @long_names)
|
87
77
|
loader.copy_to_lib
|
88
78
|
else
|
89
79
|
puts "#{d.name} is not installed locally"
|
data/lib/nu/settings.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Nu
|
5
|
+
class SettingsExtension
|
6
|
+
|
7
|
+
def self.mix_in(target)
|
8
|
+
|
9
|
+
def target.set_setting_by_path(path, value, logger)
|
10
|
+
path = path.split('.') if path.class == String
|
11
|
+
set_setting(self, path, value, logger)
|
12
|
+
end
|
13
|
+
|
14
|
+
def target.get_setting_by_path(path, logger)
|
15
|
+
path = path.split('.') if path.class == String
|
16
|
+
obj = self
|
17
|
+
path.count.times do
|
18
|
+
if path.count == 1
|
19
|
+
return obj.send(path.to_s)
|
20
|
+
else
|
21
|
+
part = path.shift
|
22
|
+
obj = obj.send(part.to_s)
|
23
|
+
return nil if obj == nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
send(name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def target.set_setting(settings_object, path, value, logger)
|
30
|
+
if path.count == 1
|
31
|
+
logger.call("Assigning value: #{value.to_s}")
|
32
|
+
begin
|
33
|
+
if value.match(/^\d*\.\d*$/)
|
34
|
+
value = Float(value.to_s)
|
35
|
+
else
|
36
|
+
value = Integer(value.to_s)
|
37
|
+
end
|
38
|
+
rescue
|
39
|
+
logger.call("Could not coerce into a number.")
|
40
|
+
value = true if value.to_s.match(/(^true$|^t$|^yes$|^y$)/i) != nil
|
41
|
+
value = false if value.to_s.match(/(^false$|^f$|^no$|^n$)/i) != nil
|
42
|
+
end
|
43
|
+
|
44
|
+
settings_object.send(path.to_s + "=", value)
|
45
|
+
else
|
46
|
+
prop = path.shift
|
47
|
+
settings_object.send(prop + "=", OpenStruct.new) if settings_object.send(prop) == nil
|
48
|
+
set_setting(settings_object.send(prop), path, value, logger)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,42 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dru Sellers
|
14
|
-
-
|
14
|
+
- Brendan Erwin
|
15
15
|
- Rob Reynold
|
16
16
|
- Travis Smith
|
17
17
|
autorequire:
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-08-
|
21
|
+
date: 2010-08-29 00:00:00 -05:00
|
22
22
|
default_executable:
|
23
|
-
dependencies:
|
24
|
-
|
25
|
-
name: thor
|
26
|
-
prerelease: false
|
27
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
hash: 59
|
33
|
-
segments:
|
34
|
-
- 0
|
35
|
-
- 13
|
36
|
-
- 8
|
37
|
-
version: 0.13.8
|
38
|
-
type: :runtime
|
39
|
-
version_requirements: *id001
|
23
|
+
dependencies: []
|
24
|
+
|
40
25
|
description: Nu manages an application's dependencies through its entire life, across many machines, systematically and repeatably
|
41
26
|
email:
|
42
27
|
- nu-net@googlegroups.com
|
@@ -48,12 +33,12 @@ extra_rdoc_files: []
|
|
48
33
|
|
49
34
|
files:
|
50
35
|
- bin/nu
|
51
|
-
- lib/nu/
|
52
|
-
- lib/nu/
|
36
|
+
- lib/nu/api.rb
|
37
|
+
- lib/nu/app.rb
|
53
38
|
- lib/nu/gem_tools.rb
|
54
39
|
- lib/nu/lib_tools.rb
|
55
40
|
- lib/nu/loader.rb
|
56
|
-
- lib/nu/
|
41
|
+
- lib/nu/settings.rb
|
57
42
|
- lib/nu.rb
|
58
43
|
has_rdoc: true
|
59
44
|
homepage: http://groups.google.com/group/nu-net
|
data/lib/nu/cli.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'FileUtils'
|
2
|
-
require 'thor'
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
module Nu
|
6
|
-
class CLI < Thor
|
7
|
-
include Thor::Actions
|
8
|
-
|
9
|
-
def initialize(*)
|
10
|
-
super
|
11
|
-
|
12
|
-
@proj = Nu::Project.new
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "install GEMNAME", "installs a gem in the 'pwd'"
|
16
|
-
method_options :location => :string, :version => :string
|
17
|
-
|
18
|
-
def install(*names)
|
19
|
-
|
20
|
-
loc = @proj.location
|
21
|
-
cl = options['location']
|
22
|
-
ver = options['version']
|
23
|
-
|
24
|
-
loc = cl unless cl.nil?
|
25
|
-
|
26
|
-
names.each do |n|
|
27
|
-
loader = Nu::Loader.new(n, loc, ver)
|
28
|
-
loader.copy_to_lib
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "uninstall GEM", "remove the specified gem from the lib folder"
|
33
|
-
def uninstall(gem)
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
desc "lib FOLDER", "where do you want to store the gems"
|
38
|
-
def lib(folder)
|
39
|
-
@proj.location= folder
|
40
|
-
end
|
41
|
-
|
42
|
-
desc "uselongnames", "turn the option of name + version number on"
|
43
|
-
def uselongnames
|
44
|
-
@proj.use_long_names
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "useshortnames", "turn the option of name + version number off"
|
48
|
-
def useshortnames
|
49
|
-
@proj.use_short_names
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.source_root
|
53
|
-
File.dirname(__FILE__)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
data/lib/nu/config.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'thor'
|
3
|
-
require 'FileUtils'
|
4
|
-
|
5
|
-
module Nu
|
6
|
-
#class Config < Thor::Group
|
7
|
-
#include Thor::Actions
|
8
|
-
|
9
|
-
#@config_file = ".nu/options.yaml"
|
10
|
-
|
11
|
-
#def self.get_config
|
12
|
-
# unless File.exists? @config_file
|
13
|
-
# FileUtils.touch @config_file
|
14
|
-
# append_file @config_file, YAML::dump({})
|
15
|
-
# end
|
16
|
-
# cd = YAML.load_file @config_file
|
17
|
-
# cd = ask_about_libdir cd
|
18
|
-
#
|
19
|
-
# save_file cd
|
20
|
-
# cd
|
21
|
-
#end
|
22
|
-
|
23
|
-
#def self.ask_about_libdir(config)
|
24
|
-
# if config['lib'].nil?
|
25
|
-
# loc = ask "Where do you want me to copy things to?"
|
26
|
-
# config = {'lib'=>loc}
|
27
|
-
# end
|
28
|
-
# config
|
29
|
-
#end
|
30
|
-
|
31
|
-
#def self.save_file(config)
|
32
|
-
# File.open(@config_file, 'w') do |out|
|
33
|
-
# YAML.dump( config, out)
|
34
|
-
# end
|
35
|
-
#end
|
36
|
-
#end
|
37
|
-
end
|
data/lib/nu/project.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'FileUtils'
|
2
|
-
|
3
|
-
module Nu
|
4
|
-
class Project
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@config_file = ".nu/options.yaml"
|
8
|
-
ensure_default_config
|
9
|
-
end
|
10
|
-
|
11
|
-
# need to meta awesome this
|
12
|
-
def location
|
13
|
-
opts = get_options
|
14
|
-
opts['lib']
|
15
|
-
end
|
16
|
-
|
17
|
-
# need to meta awesome this
|
18
|
-
def location=(name)
|
19
|
-
opts = get_options
|
20
|
-
opts['lib']=name
|
21
|
-
save_file(opts)
|
22
|
-
nil
|
23
|
-
end
|
24
|
-
|
25
|
-
#need to meta awesome this
|
26
|
-
def should_use_long_names?
|
27
|
-
opts = get_options
|
28
|
-
opts['uselongnames']
|
29
|
-
end
|
30
|
-
|
31
|
-
#need to meta awesome this
|
32
|
-
def use_long_names
|
33
|
-
opts = get_options
|
34
|
-
opts['uselongnames']=true
|
35
|
-
save_file(opts)
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
|
39
|
-
#need to meta awesome this
|
40
|
-
def use_short_names
|
41
|
-
opts = get_options
|
42
|
-
opts['uselongnames']=false
|
43
|
-
save_file(opts)
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
def add_file(name, content)
|
48
|
-
FileUtils.mkdir_p(File.dirname(name))
|
49
|
-
File.open(name, 'w'){|f| f.write(content)}
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def ensure_default_config
|
54
|
-
if File.exist? @config_file
|
55
|
-
return
|
56
|
-
end
|
57
|
-
|
58
|
-
save_file( {'lib'=>'lib','uselongnames'=>false} )
|
59
|
-
end
|
60
|
-
|
61
|
-
def get_options
|
62
|
-
YAML.load_file @config_file
|
63
|
-
end
|
64
|
-
|
65
|
-
def save_file(opts)
|
66
|
-
content = YAML::dump(opts)
|
67
|
-
File.delete @config_file if File.exist? @config_file
|
68
|
-
dir_name = File.dirname(@config_file)
|
69
|
-
FileUtils.mkdir_p(dir_name) unless File.exist? dir_name
|
70
|
-
File.open(@config_file, 'w') {|f| f.write(content) }
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|