Permalink
Browse files

Initial restructuring. Needs testing.

  • Loading branch information...
1 parent f16adca commit 64e6b48792fd02f75ff9d4a6d86a212b5519301c @brendanjerwin brendanjerwin committed Aug 29, 2010
Showing with 331 additions and 221 deletions.
  1. +3 −1 .gitignore
  2. +4 −2 bin/nu
  3. +1 −1 cycle.sh
  4. +111 −0 lib/nu/api.rb
  5. +151 −0 lib/nu/app.rb
  6. +0 −77 lib/nu/cli.rb
  7. +0 −37 lib/nu/config.rb
  8. +3 −5 lib/nu/loader.rb
  9. +0 −74 lib/nu/project.rb
  10. +55 −0 lib/nu/settings.rb
  11. +2 −2 nu.gemspec
  12. +1 −1 specs/loader.rspec
  13. +0 −21 specs/project.rspec
View
@@ -26,4 +26,6 @@ SolutionVersion.cs
spec_lib/*
.nu/*
-nu_spec.yaml
+nu_spec.yaml
+meta_data.yaml
+nuniverse.yaml
View
6 bin/nu
@@ -1,9 +1,11 @@
#!/usr/bin/ruby
-require 'nu'
+require 'app'
begin
- Nu::CLI.start
+ # Create and run the application
+ app = App.new(ARGV, STDIN, STDOUT)
+ app.run
rescue Interrupt
puts 'quitting'
exit 1
View
@@ -6,4 +6,4 @@ gem uninstall nu -a -x
gem build nu.gemspec
-gem install nu
+gem install --no-rdoc --no-ri nu
View
@@ -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
View
@@ -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
View
@@ -1,77 +0,0 @@
-require 'fileutils'
-require 'thor'
-require 'yaml'
-require File.expand_path(File.dirname(__FILE__) + "/lib_tools.rb")
-require File.expand_path(File.dirname(__FILE__) + "/gem_tools.rb")
-
-module Nu
- class CLI < Thor
- include Thor::Actions
-
- def initialize(*)
- super
-
- @proj = Nu::Project.new
- end
-
- desc "install GEMNAME", "installs a gem in the 'pwd'"
- method_options :location => :string, :version => :string
-
- def install(*names)
-
- loc = @proj.location
- cl = options['location']
- ver = options['version']
-
- loc = cl unless cl.nil?
-
- names.each do |n|
- loader = Nu::Loader.new(n, loc, ver)
- if loader.load_gem
- loader.copy_to_lib
- end
- end
- end
-
- desc "version", "display the version of this nu"
- def version
- nu_spec = Nu::GemTools.spec_for("nu")
- puts "Nu, version #{nu_spec.version}"
- end
-
- desc "report", "list the packages that are currently in the lib folder"
- def report
- puts ""
- puts "The following packages are installed:"
- puts "====================================="
- Nu::LibTools.read_specs_from_lib(@proj.location).each{|i| puts " " + i.full_name}
- puts "====================================="
- puts ""
- end
-
- desc "uninstall GEM", "remove the specified gem from the lib folder"
- def uninstall(gem)
-
- end
-
- desc "lib FOLDER", "where do you want to store the gems"
- def lib(folder)
- @proj.location = folder
- end
-
- desc "uselongnames", "turn the option of name + version number on"
- def uselongnames
- @proj.use_long_names
- end
-
- desc "useshortnames", "turn the option of name + version number off"
- def useshortnames
- @proj.use_short_names
- end
-
- def self.source_root
- File.dirname(__FILE__)
- end
-
- end
-end
Oops, something went wrong.

0 comments on commit 64e6b48

Please sign in to comment.