module Subtrac
  module Commands
    class Create
      def initialize(args, options)
        options.project = ask("What is the name of the project you would like to create? ") if options.project.nil?
        options.client = ask("Which client is this project for? ") if options.client.nil?
        use_custom_template = agree("Would you like to use a custom template for this project? [y/n]") if options.template.nil?
        if use_custom_template then
          Subtrac.load_config()
          list_of_templates = Dir.entries(File.join(Config.svn_dir,"templates"))
          
          # The new and improved choose()...
          choose do |menu|
            menu.prompt = "Which template would you like to use for this project?  "
            list_of_templates.each do |t|
              unless File.directory?(t)
                menu.choice t do options.template = t end
              end
            end
          end

          Subtrac.create_project(options.project,options.client,options.template)
        else
          Subtrac.create_project(options.project,options.client)
        end
      end
    end
  end
end