>From 5d55b5dfee0c1747c4e121c9893c8c2b2bd9d380 Mon Sep 17 00:00:00 2001
From: Gunnar Wolf <gwolf@gwolf.org>
Date: Mon, 18 Jun 2012 16:06:26 -0500
Subject: [PATCH] Ported from CommandLine::Application to OptionParser

---
 dhelp_parse.rb |   81 ++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 50 insertions(+), 31 deletions(-)

diff --git a/dhelp_parse.rb b/dhelp_parse.rb
index 3c71d32..55c3baf 100755
--- a/dhelp_parse.rb
+++ b/dhelp_parse.rb
@@ -1,4 +1,5 @@
 #!/usr/bin/ruby1.8 -w
+# -*- coding: utf-8 -*-
 
 =begin
     Documentation generator for dhelp
@@ -28,7 +29,7 @@ require 'dhelp'
 require 'dhelp/exporter/html'
 include Dhelp
 
-require 'commandline'
+require 'optparse'
 require 'find'
 require 'yaml'
 
@@ -51,43 +52,59 @@ end
 
 
 # dhelp_parse application class
-class DhelpParseApp < CommandLine::Application
+class DhelpParseApp
   DHELP_CONF_FILE    = "/etc/dhelp.conf"
   DOC_DIR                 = '/usr/share/doc'
   DOC_BASE_DHELP_DIR      = '/var/lib/doc-base/dhelp'
   DEFAULT_SEARCH_DIRS     = [DOC_DIR, DOC_BASE_DHELP_DIR]
 
+  Version = "0.2.0"
+  Author = "Esteban Manchado Velázquez"
+  Copyright = "Copyright (c) 2005-2007, Esteban Manchado Velázquez"
+  Synopsis = "[-v] [-h] -a doc-base_file1 d-b_f2 ... | -d doc-base_file1 d-b_f2 ... | -i | -r"
+  ShortDescription = "Debian online help system parser"
+  LongDescription = "Dhelp parser to add/remove/index-incrementally/fully-reindex dhelp files"
+
+
   def initialize
-    version           "0.2.0"
-    author            "Esteban Manchado Velázquez"
-    copyright         "Copyright (c) 2005-2007, Esteban Manchado Velázquez"
-    synopsis          "[-v] [-h] -a doc-base_file1 d-b_f2 ... | -d doc-base_file1 d-b_f2 ... | -i | -r"
-    short_description "Debian online help system parser"
-    long_description  "Dhelp parser to add/remove/index-incrementally/fully-reindex dhelp files"
-
-    option :help
-    option :names => %w(-a), :arity => [0,-1],
-           :opt_found => lambda {|opt, name, value| @action = :add;
-                                                    @doc_base_files = value },
-           :opt_description => "add documents registered in the given doc-base file"
-    option :names => %w(-d), :arity => [0,-1],
-           :opt_found => lambda {|opt, name, value| @action = :delete;
-                                                    @doc_base_files = value },
-           :opt_description => "remove documents registered in the given doc-base file"
-    option :names => %w(-v), :arity => [0,0],
-           :opt_found => lambda { @verbose = true },
-           :opt_description => "verbose"
-    option :names => %w(-i), :arity => [0,0],
-           :opt_found => lambda { @action = :index },
-           :opt_description => "perform deferred incremental indexing of pending registered docs"
-    option :names => %w(-r), :arity => [0,0],
-           :opt_found => lambda { @action = :reindex },
-           :opt_description => "perform full re-indexing of all registered docs"
-
-    expected_args [0,0]
-
-    @action  = nil
+    @action = nil
     @verbose = false
+
+    optparse = OptionParser.new do |opts|
+      opts.banner = "%s - %s\n\nSYNOPSIS:\n\t%s\n\n" % [$0, LongDescription, Synopsis]
+
+      opts.on('-h', '--help', 'Display this screen') {
+        puts opts
+        exit 0
+      }
+
+      opts.on('--version') {
+        puts '%s version %s' % [$0, Version]
+        exit 0
+      }
+
+      opts.on('-a FILE', 'Add documents registered in the given doc-base file'
+              ) { |files|
+        @action = :add
+        @doc_base_files = files
+      }
+
+      opts.on('-d FILE', 'Remove documents registered in the given doc-base file'
+              ) { |files|
+        @action = :delete
+        @doc_base_files = files
+      }
+
+      opts.on('-v', 'Verbose') { @verbose = true }
+
+      opts.on('-i', 'Perform deferred incremental indexing of pending registered docs'
+              ) { @action = :index }
+
+      opts.on('-r', 'Perform full re-indexing of all registered docs'
+              ) { @action = :reindex }
+    end
+
+    optparse.parse!
   end
 
   def packaged_configured?
@@ -185,3 +202,5 @@ class DhelpParseApp < CommandLine::Application
     puts "#{e.class}: #{e} (#{e.backtrace.join("\n")})"
   end
 end
+
+DhelpParseApp.new.main
-- 
1.7.10

