Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor codes around command line interface
- Loading branch information
Showing
6 changed files
with
78 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,42 @@ | ||
| var nroonga = require('./wrapped-nroonga'); | ||
| var context; | ||
|
|
||
| exports.defaultDatabasePath = process.env.HOME + '/.gcs/database/gcs'; | ||
| exports.defaultPrivilegedRanges = '127.0.0.0/8'; | ||
| exports.getContext = function(databasePath) { | ||
| return context || | ||
| (context = new nroonga.Context(databasePath || exports.defaultDatabasePath)); | ||
| var defaultDatabasePath = | ||
| exports.defaultDatabasePath = | ||
| CommandLineInterface.defaultDatabasePath = process.env.HOME + '/.gcs/database/gcs'; | ||
| var defaultPrivilegedRanges = | ||
| exports.defaultPrivilegedRanges = | ||
| CommandLineInterface.defaultPrivilegedRanges = '127.0.0.0/8'; | ||
|
|
||
| function CommandLineInterface(program) { | ||
| this.program = program; | ||
| } | ||
| CommandLineInterface.prototype = { | ||
| get databasePath() { | ||
| return this.program.databasePath || defaultDatabasePath; | ||
| }, | ||
| get context() { | ||
| return this._context || | ||
| (this._context = new nroonga.Context(this.databasePath)); | ||
| }, | ||
| get domain() { | ||
| return this._domain || | ||
| (this._domain = new Domain(this.program.domainName, this.context)); | ||
| }, | ||
|
|
||
| assertHaveDomainName: function() { | ||
| if (!this.program.domainName) { | ||
| console.log('You must specify the domain name.'); | ||
| process.exit(1); | ||
| } | ||
| }, | ||
|
|
||
| assertDomainExists: function() { | ||
| if (!this.domain.exists()) { | ||
| console.log('You must specify an existing domain name.'); | ||
| process.exit(1); | ||
| } | ||
| }, | ||
| }; | ||
| exports.CommandLineInterface = CommandLineInterface; | ||
|
|
||
| exports.Domain = require('./database/domain').Domain; |