<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.tendersync</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -14,6 +14,9 @@ Echoe.new('tendersync', Tendersync::VERSION) do |p|
 Tendersync is a utility...
 EOF
   p.version = Tendersync::VERSION
+  p.runtime_dependencies = [
+     ['mechanize','&gt;= 0.9.3'],
+  ]
   #p.rubyforge_name       = p.name # TODO this is default value
   #p.extra_deps         = [
   #   ['activesupport','&gt;= 2.0.2'],</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -7,4 +7,8 @@ require File.expand_path(File.dirname(__FILE__) + &quot;/../lib/tendersync&quot;)
 
 require &quot;tendersync/runner&quot;
 
-Tendersync::Runner.new.run
+begin
+  Tendersync::Runner.new(ARGV.dup).run
+rescue Tendersync::Runner::Error =&gt; e
+  puts e.message
+end</diff>
      <filename>bin/tendersync</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,9 @@
+require 'rubygems'
 require 'optparse'
 require 'tendersync/session'
 require 'tendersync/document'
+require 'mechanize'
+require 'yaml'
 
 class Tendersync::Runner
   class Error &lt; StandardError; end
@@ -11,55 +14,67 @@ class Tendersync::Runner
     @dry_run  = false
     @sections = []
     @username, @password = File.open(&quot;.login&quot;,&quot;r&quot;) { |f| f.read.chomp.split(&quot;:&quot;) } if File.exists? &quot;.login&quot;
-    
    
     settings = load_config_file
 
-    option_parser = OptionParser.new do |op|
+    @parser = OptionParser.new do |op|
       op.banner += &quot; command\n&quot;
-      op.on('-n',                                  &quot;Dry run&quot; )       {        @dry_run  = true }
-      op.on('-r', '--root',    '=PATH',    String, &quot;Document root&quot; ) { |dirt| settings['root'] = dir }
-      op.on('-s', '--sections','=SECTIONS',Array,  &quot;Sections&quot; )      { |list| @sections = list }
-      op.on('-u', '--username','=EMAIL',   String, &quot;Login e-mail (#{@username})&quot; ) {|str| settings['username'] = str }
-      op.on('-p', '--password','=PASS',    String,  &quot;Login password&quot; )  {|str| settings['password'] = str }
+      op.on('-n',                                  &quot;dry run&quot; )       { @dry_run  = true }
+      op.on('-s', '--sections','=SECTIONS',Array,  &quot;section names, comma separated&quot; ) { |list| @sections = list }
+      op.on('-u', '--username','=EMAIL',   String, &quot;*login e-mail&quot; ) {|str| settings['username'] = str }
+      op.on('-p', '--password','=PASS',    String, &quot;*password&quot; )     {|str| settings['password'] = str }
+      op.on(      '--root',    '=PATH',    String, &quot;*document root&quot; ) { |dir| settings['root'] = dir }
+      op.on(      '--docurl',  '=URL',     String,  &quot;*tender site URL&quot; ) { |dir| settings['docurl'] = dir }
         %Q{
+        * saved in .tendersync file for subsequent default
+        
     Commands:
 
-        pull [url, url...]   -- download documents from tender; specify a section, a page URL, or
+        pull [URL, URL...]   -- download documents from tender; specify a section, a page URL, or
                                 nothing to download all documents
-        index                -- index specified session (presently only works with --section=docs)
-        post document-names  -- post the specified document to tender; names may include wild cards
+        ls                   -- list files in specified session (presently only works with --section=docs)
+        post PATTERN         -- post the matching documents to tender
         irb                  -- drops you into IRB with a tender session &amp; related classes (for hacking/
                                 one-time tasks).  Programmers only.
-        create permalink     -- create a new tender document with the specified permalink in the section
+        create PERMALINK     -- create a new tender document with the specified permalink in the section
                                 specified by --section=... (must be only one.)
 
     }.split(/\n/).each {|line| op.separator line.chomp }
     end
     
+    begin
+      @command,*@args = *@parser.parse(argv)
+    rescue OptionParser::InvalidOption =&gt; e
+      raise Error, e.message
+    end
+    
     @username = settings['username']
     @password = settings['password']
-    @dochome = settings['dochome']
+    @dochome = settings['docurl'] &amp;&amp; settings['docurl'] =~ /^(http.*?)\/?/ &amp;&amp; $1
     @root = settings['root']
-    
-    @command,*@args = *option_parser.parse(argv)
-    
-    if @username.nil? || @password.nil? || @username.empty? || @password.empty?
+
+    case
+      when ! @username
       raise Error, &quot;Please enter a username and password.  You only need to do this once.&quot;
+      when ! @password
+      raise Error, &quot;Please enter a password.  You only need to do this once.&quot;
+      when ! @dochome
+      raise Error, &quot;Please enter a --docurl indicating the home page URL of your Tender docs.\n&quot; +
+           &quot;You only need to do this once.&quot;
     else
-      save_config_file
+      save_config_file(settings)
     end
   end
   
   def run
-    @session = Session.new
+    @session = Tendersync::Session.new @dochome
     case @command || 'help'
       when 'help'
-      raise Error, option_parser.to_s
+      raise Error, @parser.to_s
       when 'pull', 'post', 'create', 'irb', 'ls'
       send @command
     else
-      raise Error, option_parser.to_s
+      raise Error, &quot;Unknown command: #{@command}\n\n#{@parser}&quot;
     end
   end
   
@@ -134,7 +149,7 @@ class Tendersync::Runner
 
       Examples of crazy stuff you could try:
 
-          @session.pull_from_tender('troubleshooting')
+          @session.pull_from_tender('troubleshooting')  
 
           `git commit -a -m &quot;Automatic synchronization with tender&quot;`
           `git push`
@@ -173,7 +188,7 @@ EOF
       {}
     end
   end
-  def save_config_file
+  def save_config_file(settings)
     File.open(&quot;.tendersync&quot;,&quot;w&quot;) do |f|
       f.write(settings.to_yaml)
     end</diff>
      <filename>lib/tendersync/runner.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,17 +1,17 @@
+
 class Tendersync::Session
-  def initialize
+  def initialize(site)
     @agent = WWW::Mechanize.new { |a| }
-    @site       = 'http://support.newrelic.com'
-    @login_site = 'http://rpm.newrelic.com'
+    @site       = site
+    @login_site = &quot;#{site}/login&quot;
   end
   def login
     return if @logged_in
-    @agent.
-    get(&quot;#{@login_site}/session/new&quot;).
-    form_with(:action =&gt; '/session') { |login_form|
+    @agent.get(@login_site)
+    form_with(:action =&gt; '/login') { |login_form|
       login_form['email']    = $username 
       login_form['password'] = $password 
-    }.
+    }
     click_button
     @logged_in = true
   end
@@ -32,6 +32,9 @@ class Tendersync::Session
   def edit_page_for(doc_url)
     get &quot;#{@site}#{get(doc_url).links_like(%r{faqs/\d+/edit}).first}&quot;
   end
+  def all_sections
+    get &quot;#{@site}/dashboard/sections&quot;
+  end
   def pull_from_tender(section)
     login
     faq(section).collect { |doc_url|</diff>
      <filename>lib/tendersync/session.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,26 @@
 require File.dirname(__FILE__) + '/spec_helper.rb'
 
 describe Tendersync::Runner do
-
+  
   before do
     Tendersync::Runner.any_instance.stubs(:save_config_file)
   end
   
   it &quot;should process no args&quot; do
-    Tendersync::Runner.new []
+    begin
+      Tendersync::Runner.new []
+    rescue Tendersync::Runner::Error =&gt; e
+      e.message.should match(/Please enter a/)
+    end
+  end
+  
+  it &quot;should process no args&quot; do
+    begin
+      Tendersync::Runner.new []
+    rescue Tendersync::Runner::Error =&gt; e
+      e.message.should match(/Please enter a/)
+    end
   end
   
+  
 end</diff>
      <filename>spec/tendersync_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b03210063e0140b09a6751d86b86f1994d15e6de</id>
    </parent>
  </parents>
  <author>
    <name>Bill Kayser</name>
    <email>bkayser@newrelic.com</email>
  </author>
  <url>http://github.com/newrelic/tendersync/commit/904712a1bc3a18589795da2cd680bbd6416b8cf4</url>
  <id>904712a1bc3a18589795da2cd680bbd6416b8cf4</id>
  <committed-date>2009-06-24T08:11:27-07:00</committed-date>
  <authored-date>2009-06-24T08:11:27-07:00</authored-date>
  <message>working through tests</message>
  <tree>f651741a937f81c77169dddd2b8324bad4687d68</tree>
  <committer>
    <name>Bill Kayser</name>
    <email>bkayser@newrelic.com</email>
  </committer>
</commit>
