[Groonga-commit] groonga/gcs [master] Register version, usage, and options in specific order

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 6日 (月) 17:19:42 JST


SHIMODA Hiroshi	2012-08-06 17:19:42 +0900 (Mon, 06 Aug 2012)

  New Revision: d0d6988b528e867b7b3ebee82169bf5781fcd4f7
  https://github.com/groonga/gcs/commit/d0d6988b528e867b7b3ebee82169bf5781fcd4f7

  Log:
    Register version, usage, and options in specific order

  Modified files:
    lib/command-line.js

  Modified: lib/command-line.js (+14 -8)
===================================================================
--- lib/command-line.js    2012-08-06 17:08:57 +0900 (1b65752)
+++ lib/command-line.js    2012-08-06 17:19:42 +0900 (9d06cdb)
@@ -12,12 +12,7 @@ var defaultPrivilegedRanges =
 
 function CommandLineInterface() {
   this.program = program;
-  this.program
-      .version(version)
-      .option('--database-path <path>',
-              'database path [' + defaultDatabasePath + ']',
-              String,
-              defaultDatabasePath);
+  this.reservedOperations = [];
 }
 CommandLineInterface.prototype = {
   get databasePath() {
@@ -36,15 +31,26 @@ CommandLineInterface.prototype = {
   },
 
   parse: function() {
+    this.program.version(version);
+    this.reservedOperations.forEach(function(operation) {
+      this.program[operation.method].apply(this.program, operation.arguments);
+    }, this);
+    this.program
+      .option('--database-path <path>',
+              'database path [' + defaultDatabasePath + ']',
+              String,
+              defaultDatabasePath);
     this.program.parse(process.argv);
     return this;
   },
   usage: function() {
-    this.program.option.apply(this.program, arguments);
+    this.reservedOperations.push({ method:    'usage',
+                                   arguments: arguments });
     return this;
   },
   option: function() {
-    this.program.option.apply(this.program, arguments);
+    this.reservedOperations.push({ method:    'option',
+                                   arguments: arguments });
     return this;
   },
 
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
다운로드 



Groonga-commit メーリングリストの案内
Back to archive index