forked from phatboyg/nu
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial restructuring. Needs testing.
- Loading branch information
1 parent
f16adca
commit 64e6b48
Showing
13 changed files
with
331 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,6 @@ SolutionVersion.cs | |
|
||
spec_lib/* | ||
.nu/* | ||
nu_spec.yaml | ||
nu_spec.yaml | ||
meta_data.yaml | ||
nuniverse.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ gem uninstall nu -a -x | |
|
||
gem build nu.gemspec | ||
|
||
gem install nu | ||
gem install --no-rdoc --no-ri nu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
require 'rubygems' | ||
require 'ostruct' | ||
|
||
require File.expand_path(File.dirname(__FILE__) + "/lib_tools.rb") | ||
require File.expand_path(File.dirname(__FILE__) + "/gem_tools.rb") | ||
require File.expand_path(File.dirname(__FILE__) + "/settings.rb") | ||
|
||
module Nu | ||
class Api | ||
|
||
def self.out(out) | ||
@stdout = out | ||
end | ||
|
||
def self.verbose(verbose) | ||
@verbose = verbose | ||
end | ||
|
||
def self.load_project_settings(settings_file) | ||
log "Load Project Settings called: settings_file=#{settings_file}" | ||
@settings_file = settings_file | ||
@logger = lambda {|msg| log(msg)} | ||
@platforms = | ||
['net1_0', 'net1_1', 'net2_0', 'net3_0', 'net3_5', 'net4_0', | ||
'mono1_0', 'mono2_0', | ||
'silverlight_2_0', 'silverlight_3_0', 'silverlight_4_0'] | ||
|
||
@project_settings = YAML.load_file(@settings_file) if File.exist?(@settings_file) | ||
Nu::SettingsExtension.mix_in(@project_settings) | ||
|
||
#set defaults just in case they didn't load | ||
@project_settings = OpenStruct.new if @project_settings == nil | ||
@project_settings.lib = OpenStruct.new if @project_settings.lib == nil | ||
@project_settings.lib.location = './lib' if @project_settings.lib.location == nil | ||
@project_settings.lib.use_long_names = false if @project_settings.lib.use_long_names == nil | ||
|
||
if @verbose | ||
disp "Project Settings:" | ||
disp YAML.dump(@project_settings).gsub('!ruby/object:OpenStruct','').gsub(/\s*table:/,'').gsub('---','') | ||
disp "" | ||
end | ||
end | ||
|
||
def self.store_setting(name, value) | ||
log "Store Setting called: name=#{name} value=#{value}" | ||
log "Before:" | ||
load_project_settings(@settings_file) if @verbose | ||
|
||
@project_settings.set_setting_by_path(name, value, @logger) | ||
assert_project_settings | ||
|
||
File.open(@settings_file, 'w') do |out| | ||
YAML.dump(@project_settings, out) | ||
end | ||
log "After:" | ||
load_project_settings(@settings_file) | ||
end | ||
|
||
def self.assert_project_settings | ||
if @project_settings.platform | ||
@project_settings.platform = @project_settings.platform.gsub('.','_') | ||
if !@platforms.index(@project_settings.platform) | ||
disp "'#{@project_settings.platform}' is not a valid platform." | ||
exit 1 | ||
end | ||
end | ||
end | ||
|
||
def self.get_setting(name) | ||
log "Get Setting called: name=#{name}" | ||
@project_settings.get_setting_by_path(name, @logger) | ||
end | ||
|
||
def self.version_string | ||
nu_spec = Nu::GemTools.spec_for("nu") | ||
"Nubular, version #{nu_spec.version}" | ||
end | ||
|
||
def self.install_package(package_name, package_version) | ||
log "Install called: package_name=#{package_name} package_version=#{package_version}." | ||
|
||
loader = Nu::Loader.new(package_name, package_version, @project_settings.lib.location, @project_settings.lib.use_long_names) | ||
if loader.load_gem | ||
loader.copy_to_lib | ||
end | ||
|
||
end | ||
|
||
def self.output_report() | ||
log "Report called." | ||
|
||
disp "\n" | ||
disp "The following packages are installed:" | ||
disp "=====================================" | ||
Nu::LibTools.read_specs_from_lib(@project_settings.lib.location).each{|i| disp " " + i.full_name} | ||
disp "=====================================" | ||
disp "" | ||
end | ||
|
||
private | ||
|
||
def self.log(msg) | ||
disp(msg) if @verbose | ||
end | ||
|
||
def self.disp(msg) | ||
@stdout << msg + "\n" | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'optparse' | ||
require 'ostruct' | ||
require 'date' | ||
require File.expand_path(File.dirname(__FILE__) + "/api.rb") | ||
require File.expand_path(File.dirname(__FILE__) + "/loader.rb") | ||
|
||
class App | ||
|
||
attr_reader :options | ||
|
||
def initialize(arguments, stdin, stdout) | ||
|
||
#special case, they want to know our version | ||
if arguments.count == 1 && arguments[0] == '--version' | ||
output_version | ||
exit 0 | ||
end | ||
|
||
Nu::Api.out(stdout) | ||
|
||
@arguments = arguments | ||
|
||
# Set defaults | ||
@options = OpenStruct.new | ||
@options.verbose = false | ||
@options.quiet = false | ||
@commands = [] | ||
|
||
begin | ||
OptionParser.new do |opts| | ||
|
||
opts.banner = ["Usage: nu [un]install|upgrade PACKAGE [options]", | ||
"\nConfig: nu config NAME VALUE", | ||
"\nReport: nu report"] | ||
|
||
opts.on('-v', '--version VERSION','Specify version of package to install' ) do |ver| | ||
@options.package_version = ver | ||
end | ||
|
||
opts.on('-r','--report', 'Report on the packages currently installed in the lib folder') do | ||
@commands << lambda {Nu::Api.output_report} | ||
end | ||
|
||
# Specify options | ||
opts.on('-V', '--verbose') { @options.verbose = true } | ||
opts.on('-q', '--quiet') { @options.quiet = true } | ||
|
||
opts.on_tail( '-h', '--help', 'Display this screen' ) do | ||
output_help(opts) | ||
end | ||
|
||
@help_command = lambda{output_help(opts)} | ||
|
||
end.parse! | ||
rescue | ||
@help_command.call | ||
end | ||
|
||
post_process_options | ||
extract_commands | ||
end | ||
|
||
def run | ||
|
||
if arguments_valid? | ||
|
||
puts "Start at #{DateTime.now}\n\n" if @options.verbose | ||
output_version if @options.verbose | ||
output_inputs if @options.verbose | ||
|
||
Nu::Api.verbose(@options.verbose) | ||
Nu::Api.load_project_settings('nuniverse.yaml') | ||
|
||
@commands.reverse.each {|command| command.call} | ||
|
||
puts "\nFinished at #{DateTime.now}" if @options.verbose | ||
|
||
else | ||
@help_command.call | ||
end | ||
|
||
end | ||
|
||
protected | ||
|
||
def extract_commands | ||
if @arguments.count > 0 | ||
case @arguments[0].downcase | ||
when 'install' | ||
assert_param_count(2) | ||
@options.package = @arguments[1] | ||
@options.command = 'INSTALL' | ||
@commands << lambda {Nu::Api.install_package(@options.package, @options.package_version)} | ||
when 'uninstall' | ||
assert_param_count(2) | ||
@options.package = @arguments[1] | ||
@options.command = 'UNINSTALL' | ||
@commands << lambda {Nu::Api.uninstall_package(@options.package, @options.package_version)} | ||
when 'config' | ||
@options.command = 'CONFIG' | ||
if @arguments.count == 2 | ||
@commands << lambda {puts "#{@arguments[1]} = #{Nu::Api.get_setting(@arguments[1])}"} | ||
else | ||
assert_param_count(3) | ||
@commands << lambda do | ||
Nu::Api.store_setting(@arguments[1], @arguments[2]) | ||
puts "#{@arguments[1]} = #{Nu::Api.get_setting(@arguments[1])}" | ||
end if @arguments.count == 3 | ||
end | ||
end | ||
end | ||
end | ||
|
||
def assert_param_count(count) | ||
unless @arguments.count == count | ||
@help_command.call | ||
end | ||
end | ||
|
||
def post_process_options | ||
@options.verbose = false if !@options.verbose | ||
@options.verbose = false if @options.quiet | ||
end | ||
|
||
# True if required arguments were provided | ||
def arguments_valid? | ||
true if @commands.count > 0 | ||
end | ||
|
||
def output_inputs | ||
puts "Inputs:\n" | ||
|
||
@options.marshal_dump.each do |name, val| | ||
puts " #{name} = #{val}" | ||
end | ||
puts "" | ||
end | ||
|
||
def output_help(opts) | ||
output_version | ||
puts opts | ||
exit 0 | ||
end | ||
|
||
def output_version | ||
puts Nu::Api.version_string | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.