YUKI Hiroshi
null+****@clear*****
Mon Oct 15 19:46:21 JST 2012
YUKI Hiroshi 2012-10-15 19:46:21 +0900 (Mon, 15 Oct 2012) New Revision: e146c114e3b0dd62bab0fc6d9d00efcefdb3eb0a https://github.com/groonga/gcs/commit/e146c114e3b0dd62bab0fc6d9d00efcefdb3eb0a Log: Reduce duplicated codes Modified files: bin/gcs-describe-domain Modified: bin/gcs-describe-domain (+32 -51) =================================================================== --- bin/gcs-describe-domain 2012-10-15 19:38:56 +0900 (7030704) +++ bin/gcs-describe-domain 2012-10-15 19:46:21 +0900 (6cef8db) @@ -49,74 +49,55 @@ function reportStatus(domain, indexFields, defaultSearchField) { console.log('======================'); } -var domainName = commandLine.domainName; -if (domainName) { - commandLine.getDomainStatus(domainName, function(error, domain) { - if (error) - commandLine.raiseFatalError(error); - - var indexFields = null; - var defaultSearchField = null; +function reportDomains(domains) { + var indexFieldStatuses = {}; + var defaultSearchFields = {}; + var indexFieldStatusesCount = 0; + var defaultSearchFieldsCount = 0; - function tryDoReport() { - if (indexFields !== null && - defaultSearchField !== null) { + function tryDoReport() { + if (indexFieldStatusesCount == domains.length && + defaultSearchFieldsCount == domains.length) { + domains.forEach(function(domain, index) { + if (index) console.log(''); + var indexFields = indexFieldStatuses[domain.DomainName]; + var defaultSearchField = defaultSearchFields[domain.DomainName]; reportStatus(domain, indexFields, defaultSearchField); - process.exit(0); - } + }); + process.exit(0); } + } - commandLine.getIndexFieldStatuses(domainName, function(error, indexFieldStatuses) { + domains.forEach(function(domain) { + var domainName = domain.DomainName; + commandLine.getIndexFieldStatuses(domainName, function(error, indexFields) { if (error) commandLine.raiseFatalError(error); - indexFields = indexFieldStatuses; + indexFieldStatuses[domainName] = indexFields; + indexFieldStatusesCount++; tryDoReport(); }); commandLine.getDefaultSearchField(domainName, function(error, defaultSearchFieldResult) { if (error) commandLine.raiseFatalError(error); - defaultSearchField = defaultSearchFieldResult; + defaultSearchFields[domainName] = defaultSearchFieldResult; + defaultSearchFieldsCount++; tryDoReport(); }); }); +} + +var domainName = commandLine.domainName; +if (domainName) { + commandLine.getDomainStatus(domainName, function(error, domain) { + if (error) + commandLine.raiseFatalError(error); + reportDomains([domain]); + }); } else { commandLine.getDomainStatuses(function(error, domains) { if (error) commandLine.raiseFatalError(error); - var indexFieldStatuses = {}; - var defaultSearchFields = {}; - var indexFieldStatusesCount = 0; - var defaultSearchFieldsCount = 0; - - function tryDoReport() { - if (indexFieldStatusesCount == domains.length && - defaultSearchFieldsCount == domains.length) { - domains.forEach(function(domain, index) { - if (index) console.log(''); - var indexFields = indexFieldStatuses[domain.DomainName]; - var defaultSearchField = defaultSearchFields[domain.DomainName]; - reportStatus(domain, indexFields, defaultSearchField); - }); - process.exit(0); - } - } - - domains.forEach(function(domain) { - var domainName = domain.DomainName; - commandLine.getIndexFieldStatuses(domainName, function(error, indexFields) { - if (error) - commandLine.raiseFatalError(error); - indexFieldStatuses[domainName] = indexFields; - indexFieldStatusesCount++; - tryDoReport(); - }); - commandLine.getDefaultSearchField(domainName, function(error, defaultSearchFieldResult) { - if (error) - commandLine.raiseFatalError(error); - defaultSearchFields[domainName] = defaultSearchFieldResult; - defaultSearchFieldsCount++; - tryDoReport(); - }); - }); + reportDomains(domains); }); } -------------- next part -------------- HTML����������������������������... Download